New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ursa

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ursa - npm Package Compare versions

Comparing version 0.6.8 to 0.6.9

48

lib/ursa.js

@@ -232,5 +232,6 @@ // Copyright 2012 The Obvious Corporation.

function encrypt(buf, bufEncoding, outEncoding) {
function encrypt(buf, bufEncoding, outEncoding, padding) {
buf = decodeString(buf, bufEncoding);
return encodeBuffer(rsa.publicEncrypt(buf), outEncoding);
padding = padding || ursaNative.RSA_PKCS1_OAEP_PADDING;
return encodeBuffer(rsa.publicEncrypt(buf, padding), outEncoding);
}

@@ -288,5 +289,6 @@

function decrypt(buf, bufEncoding, outEncoding) {
function decrypt(buf, bufEncoding, outEncoding, padding) {
buf = decodeString(buf, bufEncoding);
return encodeBuffer(rsa.privateDecrypt(buf), outEncoding);
padding = padding || ursaNative.RSA_PKCS1_OAEP_PADDING;
return encodeBuffer(rsa.privateDecrypt(buf, padding), outEncoding);
}

@@ -617,20 +619,22 @@

module.exports = {
assertKey: assertKey,
assertPrivateKey: assertPrivateKey,
assertPublicKey: assertPublicKey,
coerceKey: coerceKey,
coercePrivateKey: coercePrivateKey,
coercePublicKey: coercePublicKey,
createKey: createKey,
createPrivateKey: createPrivateKey,
createPublicKey: createPublicKey,
createSigner: createSigner,
createVerifier: createVerifier,
equalKeys: equalKeys,
generatePrivateKey: generatePrivateKey,
isKey: isKey,
isPrivateKey: isPrivateKey,
isPublicKey: isPublicKey,
matchingPublicKeys: matchingPublicKeys,
sshFingerprint: sshFingerprint
assertKey: assertKey,
assertPrivateKey: assertPrivateKey,
assertPublicKey: assertPublicKey,
coerceKey: coerceKey,
coercePrivateKey: coercePrivateKey,
coercePublicKey: coercePublicKey,
createKey: createKey,
createPrivateKey: createPrivateKey,
createPublicKey: createPublicKey,
createSigner: createSigner,
createVerifier: createVerifier,
equalKeys: equalKeys,
generatePrivateKey: generatePrivateKey,
isKey: isKey,
isPrivateKey: isPrivateKey,
isPublicKey: isPublicKey,
matchingPublicKeys: matchingPublicKeys,
sshFingerprint: sshFingerprint,
RSA_PKCS1_PADDING: ursaNative.RSA_PKCS1_PADDING,
RSA_PKCS1_OAEP_PADDING: ursaNative.RSA_PKCS1_OAEP_PADDING,
};
{
"name": "ursa",
"version": "0.6.8",
"version": "0.6.9",
"keywords": [

@@ -19,3 +19,7 @@ "crypto", "key", "openssl", "private", "public", "rsa", "sign",

} ],
"author": "Dan Bornstein <danfuzz@milk.com>",
"author": {
"name": "Dan Bornstein",
"email": "danfuzz@milk.com",
"url": "http://www.milk.com/"
},
"maintainers": [ {

@@ -22,0 +26,0 @@ "name": "Dan Bornstein",

@@ -59,7 +59,9 @@ ursa

The usual public-encryption / private-decryption operations are always
done using padding mode `RSA_PKCS1_OAEP_PADDING`, which is the recommended
The usual public-encryption / private-decryption operations by default
use padding mode `RSA_PKCS1_OAEP_PADDING`, which is the recommended
mode for all new applications (as of this writing). Note that this mode
builds-in a random element into every encryption operation, making it
unnecessary to waste time or effort adding randomness in at a higher layer.
This default may be overridden to use the older mode `RSA_PKCS1_PADDING`
if needed.

@@ -224,3 +226,3 @@ The less well-understood private-encryption / public-decryption operations

### encrypt(buf, bufEncoding, outEncoding)
### encrypt(buf, bufEncoding, outEncoding, padding)

@@ -235,4 +237,5 @@ This performs the "public encrypt" operation on the given buffer. The

This operation is always performed using padding mode
`RSA_PKCS1_OAEP_PADDING`.
If no padding mode is specified, the default, and recommended, mode
is `ursa.RSA_PKCS1_OAEP_PADDING`. The mode
`ursa.RSA_PKCS1_PADDING` is also supported.

@@ -327,3 +330,3 @@ ### getExponent(encoding)

### decrypt(buf, bufEncoding, outEncoding)
### decrypt(buf, bufEncoding, outEncoding, padding)

@@ -336,4 +339,5 @@ This performs the "private decrypt" operation on the given buffer. The

This operation is always performed using padding mode
`RSA_PKCS1_OAEP_PADDING`.
If no padding mode is specified, the default, and recommended, mode
is `ursa.RSA_PKCS1_OAEP_PADDING`. The mode
`ursa.RSA_PKCS1_PADDING` is also supported.

@@ -419,2 +423,12 @@ ### hashAndSign(algorithm, buf, bufEncoding, outEncoding)

Constants
---------
Allowed padding modes for public encryption and
private decryption:
* `ursa.RSA_PKCS1_PADDING`
* `ursa.RSA_PKCS1_OAEP_PADDING`
Contributing

@@ -430,4 +444,4 @@ ------------

Author
------
Authors
-------

@@ -438,2 +452,6 @@ [Dan Bornstein](https://github.com/danfuzz)

With contribution from:
* [Tyler Neylon](https://github.com/tylerneylon)
License

@@ -440,0 +458,0 @@ -------

@@ -60,2 +60,11 @@ // Copyright 2012 The Obvious Corporation.

"8326357d54224ab25b9f29c1efdbc960a0968e4c9027cd507ffadd8dff93256c";
var PRIVATE_OLD_PAD_CIPHER_HEX =
"69d1c385929fc00f89aa98ae9cd8529afe884b581505acdcd4ceaa10bfda9adc" +
"79c472dd7e35bcc94f1146459c6a8d96e572116c7a62f1da5dd18cdb8f81e72b" +
"4a4649f40470e88c11b04fdf72e48c6adb44c41edc0c4c56074a041c03017f72" +
"f66a000066a4dbe888119c83f79e7cb8f667f0af1af41cf4adf21320fada9355" +
"6d056a2fdb1f5a9f5708e096a7408a115efa14f0e2f94feaa32322aa4af9c97a" +
"438d205f62317020e657c5057227a3d7e60a6a6658781cf41b0820988a4f9e8e" +
"b947c424248d231c3e43c711b0c4a4342a0fa484d0e3ded231a695250f4dafcf" +
"f9e94d02e3f74d4c509cfae24b8615e619805c9cdc9e85faed7d706dd6891383";
var PUBLIC_CIPHERTEXT_HEX =

@@ -120,2 +129,3 @@ "16b5e95a02db09e95bb5419998b3c5f450571578be271602828740242236e6aa" +

PRIVATE_CIPHERTEXT_HEX: PRIVATE_CIPHERTEXT_HEX,
PRIVATE_OLD_PAD_CIPHER_HEX: PRIVATE_OLD_PAD_CIPHER_HEX,
PRIVATE_KEY: PRIVATE_KEY,

@@ -122,0 +132,0 @@ PRIVATE_KEY_2: PRIVATE_KEY_2,

@@ -15,5 +15,6 @@ // Copyright 2012 The Obvious Corporation.

var fixture = require("./fixture");
var RsaWrap = fixture.RsaWrap;
var textToNid = fixture.ursaNative.textToNid;
var fixture = require("./fixture");
var RsaWrap = fixture.RsaWrap;
var ursaNative = fixture.ursaNative;
var textToNid = ursaNative.textToNid;

@@ -202,4 +203,8 @@

var encoded = new Buffer(fixture.PRIVATE_CIPHERTEXT_HEX, fixture.HEX);
var decoded = rsa.privateDecrypt(encoded).toString(fixture.UTF8);
var decoded = rsa.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
var encoded = new Buffer(fixture.PRIVATE_OLD_PAD_CIPHER_HEX, fixture.HEX);
var decoded = rsa.privateDecrypt(encoded, ursaNative.RSA_PKCS1_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
}

@@ -222,3 +227,3 @@

function f2() {
rsa.privateDecrypt("x");
rsa.privateDecrypt("x", ursaNative.RSA_PKCS1_OAEP_PADDING);
}

@@ -228,5 +233,10 @@ assert.throws(f2, /Expected a Buffer in args\[0]\./);

function f3() {
rsa.privateDecrypt(new Buffer("x"));
rsa.privateDecrypt(new Buffer("x"), ursaNative.RSA_PKCS1_OAEP_PADDING);
}
assert.throws(f3, /decoding error/);
function f4() {
rsa.privateDecrypt(new Buffer("x"), "str");
}
assert.throws(f4, /Expected a 32-bit integer/);
}

@@ -242,9 +252,15 @@

rsa.setPublicKeyPem(fixture.PUBLIC_KEY);
var encoded = rsa.publicEncrypt(plainBuf);
var decoded = priv.privateDecrypt(encoded).toString(fixture.UTF8);
var encoded = rsa.publicEncrypt(plainBuf, ursaNative.RSA_PKCS1_OAEP_PADDING);
var decoded = priv.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
encoded = priv.publicEncrypt(plainBuf);
decoded = priv.privateDecrypt(encoded).toString(fixture.UTF8);
encoded = priv.publicEncrypt(plainBuf, ursaNative.RSA_PKCS1_OAEP_PADDING);
decoded = priv.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
// Test with old-style padding.
var encoded = rsa.publicEncrypt(plainBuf, ursaNative.RSA_PKCS1_PADDING);
var decoded = priv.privateDecrypt(encoded, ursaNative.RSA_PKCS1_PADDING);
decoded = decoded.toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);
}

@@ -265,3 +281,3 @@

function f2() {
rsa.publicEncrypt("x");
rsa.publicEncrypt("x", ursaNative.RSA_PKCS1_OAEP_PADDING);
}

@@ -271,5 +287,10 @@ assert.throws(f2, /Expected a Buffer in args\[0]\./);

function f3() {
rsa.publicEncrypt(new Buffer(2048));
rsa.publicEncrypt(new Buffer(2048), ursaNative.RSA_PKCS1_OAEP_PADDING);
}
assert.throws(f3, /too large/);
function f4() {
rsa.publicEncrypt(new Buffer("x"), "str");
}
assert.throws(f4, /Expected a 32-bit integer/);
}

@@ -355,4 +376,4 @@

var plainBuf = new Buffer(fixture.PLAINTEXT, fixture.UTF8);
var encoded = rsa.publicEncrypt(plainBuf);
var decoded = rsa.privateDecrypt(encoded).toString(fixture.UTF8);
var encoded = rsa.publicEncrypt(plainBuf, ursaNative.RSA_PKCS1_OAEP_PADDING);
var decoded = rsa.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);

@@ -363,4 +384,4 @@

pubKey.setPublicKeyPem(rsa.getPublicKeyPem());
encoded = pubKey.publicEncrypt(plainBuf);
decoded = rsa.privateDecrypt(encoded).toString(fixture.UTF8);
encoded = pubKey.publicEncrypt(plainBuf, ursaNative.RSA_PKCS1_OAEP_PADDING);
decoded = rsa.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);

@@ -371,3 +392,3 @@

privKey.setPrivateKeyPem(rsa.getPrivateKeyPem());
decoded = privKey.privateDecrypt(encoded).toString(fixture.UTF8);
decoded = privKey.privateDecrypt(encoded, ursaNative.RSA_PKCS1_OAEP_PADDING).toString(fixture.UTF8);
assert.equal(decoded, fixture.PLAINTEXT);

@@ -374,0 +395,0 @@ }

@@ -534,2 +534,2 @@ // Copyright 2012 The Obvious Corporation.

console.log("All tests pass!");
console.log("All tests pass!");

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc