Global

Methods

CalculateAddr(pubKeyPEMnon-null) → {Buffer}

根据公钥信息计算其bitcoin地址
Parameters:
Name Type Description
pubKeyPEM string 符合PKCS#8标准的pem格式公钥信息,或符合X.509标准的公钥证书信息,目前只支持EC-secp256k1曲线
Source:
Returns:
bitcoin地址的Buffer数据
Type
Buffer

CreateCertificate(certFields, creatoropt, cbopt) → {string}

生成符合X.509标准的证书信息
Parameters:
Name Type Attributes Description
certFields Object 证书的具体信息,
Properties
Name Type Attributes Description
serialNumber number 证书序列号
sigAlg string 签发证书时使用的签名算法
issuerDN string 符合X500标准的代表证书发行方身份标识的Distinguished Name
subjectDN string 符合X500标准的代表证书拥有方标识的Distinguished Name
notBefore number 代表证书有效性起始时间的unix时间戳(秒)
notAfter number 代表证书有效性终止时间的unix时间戳(秒)
subjectPubKey Object 证书拥有方的公钥对象,使用jsrsasign提供的pubKeyObj
issuerPrvKey Object 证书发行方的私钥对象,使用jsrsasign提供的prvKeyObj
extensions Object <optional>
证书扩展,jsrsasign支持的扩展属性(https://kjur.github.io/jsrsasign/api/symbols/KJUR.asn1.x509.TBSCertificate.html#appendExtension), 如: { BasicConstraints: { cA: true, critical: true }, KeyUsage: { names: ["digitalSignature", "keyCertSign"] }, AuthorityKeyIdentifier: {kid: "1234ab..."}, SubjectAltName: {critical: true, array: [{uri: "http://aaa.com"}, {uri: "http://bbb.com"}]} }
gmUserID string <optional>
证书拥有者的id标识, 当creator为gm时,需要该属性,并且不需要其他属性; 当creator为jsrsasign时,不需要该属性
creator string <optional>
证书生成者,支持使用jsrsasign或gm(即国密),默认使用jsrsasign
cb gmCertificateCallback <optional>
回调函数,gm证书生成实现是异步的,所以当creator为gm时,需要提供该参数
Source:
Returns:
certPEM pem格式的证书信息,当creator为jsrsasign时,将返回该信息
Type
string

CreateCSR(params) → {string}

生成PEM格式的证书签名请求(Certificate Signing Request, CSR)信息
Parameters:
Name Type Description
params Object 生成csr所需参数
Properties
Name Type Description
subject string 证书拥有者唯一标识名
subjectPubKey string 证书拥有者PEM格式的公钥信息
signAlg string 生成csr的签名算法
subjectPrvKey string 证书拥有者PEM格式的私钥信息(无加密)
Source:
Returns:
PEM格式的csr信息
Type
string

CreateKeypair(algopt, keyLenOrCurveopt) → {Object}

创建非对称密钥对,支持RSA与EC密钥对生成
Parameters:
Name Type Attributes Default Description
alg string <optional>
EC 密钥对生成算法,RSA或EC,默认使用EC
keyLenOrCurve string | number <optional>
secp256k1 指定密钥长度(针对RSA)或曲线名(针对EC), 默认使用EC secp256k1曲线
Source:
Returns:
keypair 含有jsrsasign提供的prvKeyObj与pubKeyObj对象
Type
Object

CreateSelfSignedCertificate(certFields) → {string}

生成符合X.509标准的自签名证书信息
Parameters:
Name Type Description
certFields Object 证书具体信息
Properties
Name Type Attributes Description
serialNumber number 证书序列号
sigAlg string 证书签名算法
DN string 符合X500标准的代表证书所有者身份标识的Distinguished Name
notBefore number 代表证书有效性起始时间的unix时间戳
notAfter number 代表证书有效性终止时间的unix时间戳
keypair Object 证书拥有方的密钥对,含有jsrsasign提供的prvKeyObj和pubKeyObj对象
extensions Object <optional>
v3证书扩展属性
Source:
Returns:
certPEM pem格式的自签名证书信息
Type
string

GetCSRInfoFromPEM(csrPEM) → {Object}

从PEM格式的csr中获取csr信息
Parameters:
Name Type Description
csrPEM string PEM格式的csr信息
Source:
Returns:
csrInfo 解析后的csr信息(JSON) csrInfo.pubkey.obj - 证书拥有者公钥对象(jsrsasign提供的RSAKey, KJUR.crypto.{ECDSA,DSA}) csrInfo.pubkey.hex - 证书拥有者公钥的hex格式 csrInfo.subject.name - 证书拥有者唯一标识名 csrInfo.subject.hex - 证书拥有者唯一标识名的hex格式
Type
Object

GetHashVal(getHashParamsnon-null) → {Buffer}

根据指定的密码学哈希算法为给定数据计算哈希值
Parameters:
Name Type Description
getHashParams Object 计算哈希值所需参数
Properties
Name Type Attributes Description
data Buffer | string 待对其计算哈希值的原数据
alg string <optional>
待使用的密码学哈希算法,默认为sha256
provider string <optional>
密码学哈希算法的提供者,支持nodecrypto、jsrsasign以及gm
  • nodecrypto,NodeJS内建的crypto工具,默认使用该provider,支持openssl提供的hash算法, 可在终端使用命令`openssl list-message-digest-algorithms`(1.0.2版) 或`openssl list -digest-algorithms`(1.1.0版)查看支持的哈希算法
  • jsrsasign,开源js加密工具(https://kjur.github.io/jsrsasign), 支持的哈希算法如 https://kjur.github.io/jsrsasign/api/symbols/KJUR.crypto.MessageDigest.html所示
  • gm,国密算法加密工具,支持sm3哈希算法
  • cb gmGetHashCallback <optional>
    sm3计算服务为异步实现,当使用sm3时需提供回调方法
    Source:
    Returns:
    digest 结果哈希值,若使用sm3将返回undefined
    Type
    Buffer

    GetKeyPEM(keyObj, passWordopt) → {string}

    获得PEM格式的私钥或公钥信息
    Parameters:
    Name Type Attributes Description
    keyObj Object prvKeyObj或pubKeyObj
    passWord string <optional>
    私钥保护密码,当需要生成加密私钥信息时需提供该参数, 目前是由jsrsasign使用PBKDF2_HmacSHA1_3DES算法对私钥进行加密
    Source:
    Returns:
    keyPEM 符合PKCS#8标准的密钥信息
    Type
    string

    ImportCertificate(certPEM) → {Object}

    导入已有的公钥证书信息
    Parameters:
    Name Type Description
    certPEM string 符合X.509标准的公钥证书信息
    Source:
    Returns:
    x509 jsrsasign提供的X509对象实例
    Type
    Object

    ImportKey(keyPEM, passWordopt) → {Object}

    导入已有非对称密钥
    Parameters:
    Name Type Attributes Description
    keyPEM string 使用符合PKCS#8标准的pem格式私钥信息获取私钥对象,支持导入使用PBKDF2_HmacSHA1_3DES加密的pem格式私钥信息 使用符合PKCS#8标准的pem格式公钥信息或符合X.509标准的pem格式证书信息获取公钥对象
    passWord string <optional>
    私钥保护密码, 当导入已加密私钥时,需要提供该参数
    Source:
    Returns:
    keyObj密钥对象,prvkeyObj或pubKeyObj
    Type
    Object

    Sign(signParams) → {Buffer}

    根据指定私钥和签名算法,对给定数据进行签名
    Parameters:
    Name Type Description
    signParams Object 签名所需参数
    Properties
    Name Type Attributes Description
    prvKey Object | string 私钥信息,支持使用jsrsasign提供的私钥对象, 或直接使用符合PKCS#5的未加密pem格式DSA/RSA私钥,符合PKCS#8的未加密pem格式RSA/ECDSA私钥,当使用gm签名算法时该参数应为null
    data string | Buffer 待被签名的数据
    alg string <optional>
    签名算法,默认使用"SHA1"(NodeJS)或"ecdsa-with-SHA1"(Browser), 国密签名算法为sm2-with-SM3
    provider string <optional>
    签名算法的提供者,支持使用jsrsasign或node内建的crypto(默认使用),以及gm国密签名算法工具
    gmUserID string <optional>
    国密签名算法需要的用户标识,该标识是到gm websocket server查找到其对应国密私钥的唯一标识
    cb gmSignCallback <optional>
    国密签名算法支持为异步实现,当使用国密签名算法时,需要使用该回调方法
    Source:
    Returns:
    signature 签名结果值,当使用非国密签名时,会返回该结果
    Type
    Buffer

    VerifyCertificateSignature(certPEM, pubKey) → {boolean}

    验证证书签名信息
    Parameters:
    Name Type Description
    certPEM string 符合X509标准的公钥证书信息
    pubKey Object 证书签发者的公钥对象
    Source:
    Returns:
    证书签名验证结果
    Type
    boolean

    VerifySign(verifySignatureParams) → {boolean}

    验证签名
    Parameters:
    Name Type Description
    verifySignatureParams Object 验证签名所需参数
    Properties
    Name Type Attributes Description
    pubKey Object | string 公钥信息,支持使用jsrsasign提供的公钥对象, 或直接使用符合PKCS#8的pem格式DSA/RSA/ECDSA公钥,符合X.509的PEM格式包含公钥信息的证书
    sigValue Buffer 签名结果
    data string | Buffer 被签名的原数据
    alg string <optional>
    签名算法,默认使用"SHA1"(NodeJS)或"ecdsa-with-SHA1"(Browser)
    provider string <optional>
    签名算法的提供者, 支持使用jsrsasign或node内建的crypto(默认使用),待支持使用国密算法提供者
    Source:
    Returns:
    isValid 签名真实性鉴定结果
    Type
    boolean

    Type Definitions

    gmCertificateCallback(certPEM)

    Parameters:
    Name Type Description
    certPEM string pem格式证书
    Source:

    gmGetHashCallback(sm3HashVal)

    Parameters:
    Name Type Description
    sm3HashVal string hex格式的国密算法哈希值
    Source:

    gmSignCallback(signature)

    Parameters:
    Name Type Description
    signature string hex格式签名信息
    Source:

    websocketCallback(eventMessage)

    Parameters:
    Name Type Description
    eventMessage Object
    Source: