function CryptographyActiveX(objectId, classid, cabFilePath, version) {
    this.objectName = objectId;
    this.clientCertificateInitialized = false;
    this.serverCertificateInitialized = false;
    this.operationStatus = "";
    document.writeln("<OBJECT id='" + this.objectName + "'");
    document.writeln("style='LEFT: 0px; WIDTH: 1px; TOP: 0px; HEIGHT: 1px'");
    document.writeln("height='1'");
    document.writeln("width='1'");
    document.writeln("classid='clsid:" + classid + "'");
    document.writeln("CODEBASE='" + cabFilePath + "#version=" + version + "'>");
    document.writeln("<param name='_Version' value='65536'>");
    document.writeln("<param name='_ExtentX' value='260'>");
    document.writeln("<param name='_ExtentY' value='260'>");
    document.writeln("<param name='_StockProps' value='0'>");
    document.writeln("</OBJECT>");
}

CryptographyActiveX.prototype.getErrorCode = function() {
    return document[this.objectName].ErrorCode;
};

CryptographyActiveX.prototype.getErrorMessage = function() {
    return document[this.objectName].ErrorMessage;
};

CryptographyActiveX.prototype.showOperationStatus = function() {
    var operationStatus = this.operationStatus;
    this.operationStatus = "";
    window.alert(operationStatus);
};

CryptographyActiveX.prototype.getOperationStatus = function() {
    var operationStatus = this.operationStatus;
    this.operationStatus = "";
    return operationStatus;
};

CryptographyActiveX.prototype.setOperationStatus = function(operationStatus) {
    this.operationStatus = operationStatus;
};

CryptographyActiveX.prototype.checkOperationStatus = function() {
    var isSuccess = false;
    if (this.operationStatus == "") {
        isSuccess = (this.getErrorCode() == 0);
        if (!isSuccess) {
            this.operationStatus = this.getErrorMessage();
        }
    }
    if (!isSuccess) {
        this.showOperationStatus();
    }
    return isSuccess;
};

CryptographyActiveX.prototype.selectClientCertificate = function() {
    var errorCode = document[this.objectName].EnumClientCert();
    if (errorCode == 0) {
        this.clientCertificateInitialized = true;
    }
    return (errorCode == 0);
};

CryptographyActiveX.prototype.enumClientCertificate = function() {
    var errorCode = document[this.objectName].EnumClientCert();
    if (errorCode == 0) {
        this.clientCertificateInitialized = true;
    }
    return (errorCode == 0);
};
//??SN????????
CryptographyActiveX.prototype.initializeClientCertificate = function(certificateSerialNumber) {
    var errorCode = document[this.objectName].InitClientCertByCertSN(certificateSerialNumber);
    if (errorCode == 0) {
        this.clientCertificateInitialized = true;
    }
    return (errorCode == 0);
};
//???????????????????????
CryptographyActiveX.prototype.initializeServerCertificate = function(serverSigntureCertificate, serverEncryptCertificate) {
    var errorCode = document[this.objectName].InitServerCert(serverSigntureCertificate, serverEncryptCertificate);
    if (errorCode == 0) {
        this.serverCertificateInitialized = true;
    }
    return (errorCode == 0);
};
//
CryptographyActiveX.prototype.checkClientCertificateStatus = function() {
    if (!this.clientCertificateInitialized) {
        this.selectClientCertificate();
    }
    return this.clientCertificateInitialized;
};
//
CryptographyActiveX.prototype.checkServerCertificateStatus = function() {
    if (!this.serverCertificateInitialized) {
        this.setOperationStatus("????????????????????????????????????????????????");
    }
    return this.serverCertificateInitialized;
};
//?????????
CryptographyActiveX.prototype.getClientSignCertificate = function() {
    var certificate = null;
    if (this.checkClientCertificateStatus()) {
        certificate = document[this.objectName].ClientSignCert;
    }
    return certificate;
};
//??????????SN
CryptographyActiveX.prototype.getClientSignCertificateSN = function() {
    var certificateSN = null;
    if (this.checkClientCertificateStatus()) {
        certificateSN = document[this.objectName].ClientSignCertSN;
    }
    return certificateSN;
};
//??????????CN
CryptographyActiveX.prototype.getClientSignCertificateCN = function() {
    var certificateCN = null;
    if (this.checkClientCertificateStatus()) {
        certificateCN = document[this.objectName].ClientSignCertCN;
    }
    return certificateCN;
};
//??????????DN
CryptographyActiveX.prototype.getClientSignCertificateDN = function() {
    var certificateDN = null;
    if (this.checkClientCertificateStatus()) {
        certificateDN = document[this.objectName].ClientSignCertDN;
    }
    return certificateDN;
};
//?????????
CryptographyActiveX.prototype.getClientEncryptCertificate = function() {
    var certificate = null;
    if (this.checkClientCertificateStatus()) {
        certificate = document[this.objectName].ClientEncCert;
    }
    return certificate;
};
//??????
CryptographyActiveX.prototype.signData = function(sourceData) {
    var signedData = null;
    if (this.checkClientCertificateStatus()) {
        signedData = document[this.objectName].SignData(sourceData);
    }
    return signedData;
};
//????
CryptographyActiveX.prototype.verifySignature = function(sourceData, signedData) {
    if (this.checkClientCertificateStatus()) {
        return document[this.objectName].VerifySignEx(sourceData, signedData, -1);
    }
};
//???????
CryptographyActiveX.prototype.clientEncryptData = function(sourceData) {
    var encryptedData = null;
    if (this.checkClientCertificateStatus()) {
        encryptedData = document[this.objectName].EncryptData(sourceData, 1);
    }
    return encryptedData;
};
//????????
CryptographyActiveX.prototype.serverEncryptData = function(sourceData) {
    var encryptedData = null;
    if (this.checkServerCertificateStatus) {
        encryptedData = document[this.objectName].EncryptData(sourceData, 2);
    }
    return encryptedData;
};
//???????
CryptographyActiveX.prototype.decryptData = function(encryptedData) {
    var sourceData = null;
    if (this.checkClientCertificateStatus()) {
        sourceData = document[this.objectName].DecryptData(encryptedData);
    }
    return sourceData;
};
//??????
CryptographyActiveX.prototype.signEncryptData = function(sourceData) {
    var envelopedData = null;
    if (this.checkServerCertificateStatus) {
        if (this.checkClientCertificateStatus()) {
            envelopedData = document[this.objectName].SignEnvData(sourceData);
        }
    }
    return envelopedData;
};
//??????
CryptographyActiveX.prototype.verifyDecryptData = function(envelopedData) {
    var sourceData = null;
    if (this.checkServerCertificateStatus) {
        if (this.checkClientCertificateStatus()) {
            sourceData = document[this.objectName].VfyDecData(envelopedData);
        }
    }
    return sourceData;
};
//??????
CryptographyActiveX.prototype.signEncryptFile = function(sourceFileName, envelopedFileName) {
    if (this.checkServerCertificateStatus) {
        if (this.checkClientCertificateStatus()) {
            document[this.objectName].SignEncFile(sourceFileName, envelopedFileName);
        }
    }
};
//??????
CryptographyActiveX.prototype.verifyDecryptFile = function(envelopedFileName, sourceFileName) {
    if (this.checkServerCertificateStatus) {
        if (this.checkClientCertificateStatus()) {
            document[this.objectName].VfyDecFile(envelopedFileName, sourceFileName);
        }
    }
};

