You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42-51Lines changed: 42 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Based on jsbn library from Tom Wu http://www-cs-students.stanford.edu/~tjw/jsbn/
8
8
* Generating keys
9
9
* Supports long messages for encrypt/decrypt
10
10
* Signing and verifying
11
-
11
+
12
12
13
13
## Example
14
14
@@ -48,19 +48,48 @@ var NodeRSA = require('node-rsa');
48
48
49
49
var key =newNodeRSA([key], [options]);
50
50
```
51
+
51
52
**key** - parameters of a generated key or the key in PEM format.<br/>
53
+
**options** - additional settings
54
+
55
+
#### Options
56
+
You can specify some options when key create (by second constructor argument) or over `key.setOptions()` method.
57
+
58
+
***environment** - working environment, `'browser'` or `'node'`. Default autodetect.
59
+
***encryptionScheme** - padding scheme for encrypt/decrypt. Can be `'pkcs1_oaep'` or `'pkcs1'`. Default `'pkcs1_oaep'`.
60
+
***signingScheme** - scheme used for signing and verifying. Can be `'pkcs1'` or `'pss'` or 'scheme-hash' format string (eg `'pss-sha1'`). Default `'pkcs1-sha256'`, or, if chosen pss: `'pss-sha1'`.
61
+
62
+
**Advanced options:**<br/>
63
+
You also can specify advanced options for some schemes like this:
64
+
```
65
+
options = {
66
+
encryptionScheme: {
67
+
scheme: 'pkcs1_oaep', //scheme
68
+
hash: 'md5', //hash using for scheme
69
+
mgf: function(...) {...} //mask generation function
70
+
},
71
+
signingScheme: {
72
+
scheme: 'pss', //scheme
73
+
hash: 'sha1', //hash using for scheme
74
+
saltLength: 20 //salt length for pss sign
75
+
}
76
+
}
77
+
```
52
78
53
-
#### "Empty" key
79
+
This lib supporting next hash algorithms: `'md5'`, `'ripemd160'`, `'sha1'`, `'sha256'`, `'sha512'` in browser and node environment and additional `'md4'`, `'sha'`, `'sha224'`, `'sha384'` in node only.
80
+
81
+
82
+
#### Creating "empty" key
54
83
```javascript
55
84
var key =newNodeRSA();
56
85
```
57
86
58
-
### Generate new key 512bit-length and with public exponent 65537
87
+
####Generate new key 512bit-length and with public exponent 65537
59
88
```javascript
60
89
var key =newNodeRSA({b:512});
61
90
```
62
91
63
-
### Load key from PEM string
92
+
####Load key from PEM string
64
93
65
94
```javascript
66
95
var key =newNodeRSA('-----BEGIN RSA PRIVATE KEY-----\n'+
@@ -116,13 +145,6 @@ Return max data size for encrypt in bytes.
116
145
117
146
### Encrypting/decrypting
118
147
119
-
*As of v0.1.55 the default encryption scheme is RSAES-OAEP using sha1 and mgf1.
120
-
PKCS1 is still available with the following configuring*
**encoding** - encoding for result string. Can also take `'buffer'` for raw Buffer object, or `'json'` for automatic JSON.parse result. Default `'buffer'`.
140
162
141
163
### Signing/Verifying
142
-
143
-
*As of v0.1.55 the default signature scheme is RSASSA-PSS using sha1.
144
-
PKCS1 is still available with the following configuring*
145
-
146
-
```javascript
147
-
key.schemeSignature=NodeRSA.RSA.PKCS1.Default;
148
-
```
149
-
150
164
```javascript
151
165
key.sign(buffer, [encoding], [source_encoding]);
152
166
```
@@ -161,44 +175,21 @@ Return result of check, `true` or `false`.<br/>
161
175
**source_encoding** - same as for `encrypt` method.<br/>
162
176
**signature_encoding** - encoding of given signature. May be `'buffer'`, `'binary'`, `'hex'` or `'base64'`. Default `'buffer'`.
163
177
164
-
### Changing Encryption/Signature schemes.
165
-
166
-
Schemes are the way RSA packs up it's data before encrypting/decrypting/signing/verifying and there are a few ways that it can do it. The most common are RSAES-OAEP, RSASSA-PSS, RSAES-PKCS1-v1_5(encryption/decryption), and RSASSA-PKCS1-v1_5(signing/verifying).
167
-
As of v0.1.55 these 4 mentioned schemes are included in the package with the ability to easily add more later and by users. See below for how to configure NodeRSA to use these different schemes.
168
-
169
-
*Note: The default encryption / signature schemes have been changed from PKCS1 to the more secure OAEP(encryption) and PSS(signature) schemes as per the recommendations of the spec, this can be breaking.*
170
-
171
-
```javascript
172
-
key.schemeSignature=NodeRSA.RSA.PSS.Default; // This is an object that has been automatically instantiated and has the default settings for PSS signing.
173
-
key.schemeSignature=NodeRSA.RSA.PKCS1.Default; // This is an object that has been automatically instantiated and has the default settings for PKCS1 signing/encrypting.
174
-
175
-
key.schemeEncryption=NodeRSA.RSA.OAEP.Default; // This is an object that has been automatically instantiated and has the default settings for OAEP encrypting.
176
-
key.schemeEncryption=NodeRSA.RSA.PKCS1.Default; // This is an object that has been automatically instantiated and has the default settings for PKCS1 signing/encrypting.
177
-
```
178
-
To change schemes between the various defaults, each provided scheme class has a property named "Default" that provides a scheme object with the default settings for that scheme.
179
-
180
-
```javascript
181
-
var pssMD5Scheme =newNodeRSA.RSA.PSS({
182
-
// The options a scheme accepts should be documented in the scheme definition.
183
-
hash:"md5", // Use a different type of hashing function instead of sha1
184
-
mgf: customMaskGenerationFunction // Use a custom mask generation function that accepts 3 parameters (seed, maskLength, hashFunction)
185
-
});
186
-
key.schemeSignature= pssMD5Scheme;
187
-
key2.schemeSignature= pssMD5Scheme;
188
-
```
189
-
Schemes can also be initialized with custom options and can be shared between keys.
190
-
191
178
## Contributing
192
179
193
180
Questions, comments, bug reports, and pull requests are all welcome.
194
181
195
182
## Changelog
196
183
197
-
### 0.1.55
198
-
***The default schemes used to encrypt and sign data have changed from PKCS1 to the recommended OAEP and PSS standards**
199
-
* Overhauled the rsa.js library to allow for schemes and to allow for easy addition of schemes in the future and custom schemes.
200
-
* Modified NodeRSA functions to work with new rsa.js file.
201
-
* All changes should be backwards compatible
184
+
### 0.2.0
185
+
* Added PKCS1_OAEP encrypting/decrypting support
186
+
***PKCS1_OAEP now default scheme, you need to specify 'encryptingScheme' option to 'pkcs1' for compatibility with 0.1.x version of NodeRSA**
187
+
* Added PSS signing/verifying support
188
+
* Signing now supports `'md5'`, `'ripemd160'`, `'sha1'`, `'sha256'`, `'sha512'` hash algorithms in both environments
189
+
and additional `'md4'`, `'sha'`, `'sha224'`, `'sha384'` for nodejs env.
190
+
*`options.signingAlgorithm` rename to `options.signingScheme`
191
+
* Added `encryptingScheme` option
192
+
* Property `key.options` now mark as private. Added `key.setOptions(options)` method.
202
193
203
194
### 0.1.54
204
195
* Added support for loading PEM key from Buffer (`fs.readFileSync()` output)
0 commit comments