Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: length of the result buffer may less than the nodeCrypto's #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ function _testIt (keys, message, t) {
var pub = keys.public
var priv = keys.private
t.test(message.toString(), function (t) {
t.plan(8)
t.plan(10)

var myEnc = myCrypto.publicEncrypt(pub, message)
var nodeEnc = nodeCrypto.publicEncrypt(pub, message)
t.equals(myEnc.length, nodeEnc.length, 'my public encrypted length node public encrypted length')
t.equals(myCrypto.privateDecrypt(priv, myEnc).toString('hex'), message.toString('hex'), 'my decrypter my message')
t.equals(myCrypto.privateDecrypt(priv, nodeEnc).toString('hex'), message.toString('hex'), 'my decrypter node\'s message')
t.equals(nodeCrypto.privateDecrypt(priv, myEnc).toString('hex'), message.toString('hex'), 'node decrypter my message')
t.equals(nodeCrypto.privateDecrypt(priv, nodeEnc).toString('hex'), message.toString('hex'), 'node decrypter node\'s message')
myEnc = myCrypto.privateEncrypt(priv, message)
nodeEnc = nodeCrypto.privateEncrypt(priv, message)
t.equals(myEnc.length, nodeEnc.length, 'my public private length node private encrypted length')
t.equals(myCrypto.publicDecrypt(pub, myEnc).toString('hex'), message.toString('hex'), 'reverse methods my decrypter my message')
t.equals(myCrypto.publicDecrypt(pub, nodeEnc).toString('hex'), message.toString('hex'), 'reverse methods my decrypter node\'s message')
t.equals(nodeCrypto.publicDecrypt(pub, myEnc).toString('hex'), message.toString('hex'), 'reverse methods node decrypter my message')
Expand Down
2 changes: 1 addition & 1 deletion withPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function withPublic (paddedMsg, key) {
.toRed(BN.mont(key.modulus))
.redPow(new BN(key.publicExponent))
.fromRed()
.toArray())
.toArray('be', key.modulus.byteLength()))
}

module.exports = withPublic