[英]Equivalent of nodejs crypto crypto.createSign in Python
[英]Valid algorithm input strings for Node.js' crypto.createSign()
我正在為項目使用節點的加密簽名,並且一直在嘗試考慮各種算法的起伏。 crypto.createSign()
的描述如下:
創建並返回使用給定算法的Sign對象。 在最新的OpenSSL版本中,
openssl list-public-key-algorithms
將顯示可用的簽名算法。 一個示例是“ RSA-SHA256”。
不幸的是,“ RSA-SHA256”不是openssl list-public-key-algorithms
(如下所示)的輸出值之一。
那么該函數的有效值是多少,或者如何從下面的列表中提取它們?
OpenSSL list result:
Name: OpenSSL RSA method
Type: Builtin Algorithm
OID: rsaEncryption
PEM string: RSA
Name: rsa
Type: Alias to rsaEncryption
Name: OpenSSL PKCS#3 DH method
Type: Builtin Algorithm
OID: dhKeyAgreement
PEM string: DH
Name: dsaWithSHA
Type: Alias to dsaEncryption
Name: dsaEncryption-old
Type: Alias to dsaEncryption
Name: dsaWithSHA1-old
Type: Alias to dsaEncryption
Name: dsaWithSHA1
Type: Alias to dsaEncryption
Name: OpenSSL DSA method
Type: Builtin Algorithm
OID: dsaEncryption
PEM string: DSA
Name: OpenSSL EC algorithm
Type: Builtin Algorithm
OID: id-ecPublicKey
PEM string: EC
Name: OpenSSL HMAC method
Type: Builtin Algorithm
OID: hmac
PEM string: HMAC
Name: OpenSSL CMAC method
Type: Builtin Algorithm
OID: cmac
PEM string: CMAC
好吧,經過一番蠻力和合理的猜測之后,有效算法輸入字符串的結構似乎毫無意義。 開始看起來像規則的情況有很多例外。 如果省略了公鑰算法,則RSA似乎是默認值。 下面是不起作用的值的不完整列表:
僅公共密鑰算法:
僅散列:
公鑰算法哈希對:
我不是密碼學家,所以RSA可能需要明確的哈希選擇,或者DSA與sha512或md5不兼容,但是我發現這些不一致之處更多是由openSSL的實現引起的。
我認為Node文檔是錯誤的。 對於crypto.createSign()
,使用以下命令列出可能性:
openssl list-message-digest-algorithms
運行crypto.getHashes()
以獲取可用簽名算法的列表。
例如,如果您在Node v8.15.0
運行它, v8.15.0
得到:
[ 'DSA',
'DSA-SHA',
'DSA-SHA1',
'DSA-SHA1-old',
'RSA-MD4',
'RSA-MD5',
'RSA-MDC2',
'RSA-RIPEMD160',
'RSA-SHA',
'RSA-SHA1',
'RSA-SHA1-2',
'RSA-SHA224',
'RSA-SHA256',
'RSA-SHA384',
'RSA-SHA512',
'dsaEncryption',
'dsaWithSHA',
'dsaWithSHA1',
'dss1',
'ecdsa-with-SHA1',
'md4',
'md4WithRSAEncryption',
'md5',
'md5WithRSAEncryption',
'mdc2',
'mdc2WithRSA',
'ripemd',
'ripemd160',
'ripemd160WithRSA',
'rmd160',
'sha',
'sha1',
'sha1WithRSAEncryption',
'sha224',
'sha224WithRSAEncryption',
'sha256',
'sha256WithRSAEncryption',
'sha384',
'sha384WithRSAEncryption',
'sha512',
'sha512WithRSAEncryption',
'shaWithRSAEncryption',
'ssl2-md5',
'ssl3-md5',
'ssl3-sha1',
'whirlpool' ]
在Node v10.15.1
您將獲得:
[ 'RSA-MD4',
'RSA-MD5',
'RSA-MDC2',
'RSA-RIPEMD160',
'RSA-SHA1',
'RSA-SHA1-2',
'RSA-SHA224',
'RSA-SHA256',
'RSA-SHA384',
'RSA-SHA512',
'blake2b512',
'blake2s256',
'md4',
'md4WithRSAEncryption',
'md5',
'md5-sha1',
'md5WithRSAEncryption',
'mdc2',
'mdc2WithRSA',
'ripemd',
'ripemd160',
'ripemd160WithRSA',
'rmd160',
'sha1',
'sha1WithRSAEncryption',
'sha224',
'sha224WithRSAEncryption',
'sha256',
'sha256WithRSAEncryption',
'sha384',
'sha384WithRSAEncryption',
'sha512',
'sha512WithRSAEncryption',
'ssl3-md5',
'ssl3-sha1',
'whirlpool' ]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.