Skip to content

Commit 4f7393a

Browse files
committed
Merge branch 'BAM5-master'
Fixes bugs
1 parent 0449fcb commit 4f7393a

File tree

13 files changed

+1168
-1115
lines changed

13 files changed

+1168
-1115
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
.idea
3+
.tmp
34
node_modules/

README.md

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Based on jsbn library from Tom Wu http://www-cs-students.stanford.edu/~tjw/jsbn/
88
* Generating keys
99
* Supports long messages for encrypt/decrypt
1010
* Signing and verifying
11-
11+
1212

1313
## Example
1414

@@ -48,19 +48,48 @@ var NodeRSA = require('node-rsa');
4848

4949
var key = new NodeRSA([key], [options]);
5050
```
51+
5152
**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+
```
5278

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
5483
```javascript
5584
var key = new NodeRSA();
5685
```
5786

58-
### Generate new key 512bit-length and with public exponent 65537
87+
#### Generate new key 512bit-length and with public exponent 65537
5988
```javascript
6089
var key = new NodeRSA({b: 512});
6190
```
6291

63-
### Load key from PEM string
92+
#### Load key from PEM string
6493

6594
```javascript
6695
var key = new NodeRSA('-----BEGIN RSA PRIVATE KEY-----\n'+
@@ -116,13 +145,6 @@ Return max data size for encrypt in bytes.
116145

117146
### Encrypting/decrypting
118147

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*
121-
122-
```javascript
123-
key.schemeEncryption = NodeRSA.RSA.PKCS1.Default;
124-
```
125-
126148
```javascript
127149
key.encrypt(buffer, [encoding], [source_encoding]);
128150
```
@@ -139,14 +161,6 @@ Return decrypted data.<br/>
139161
**encoding** - encoding for result string. Can also take `'buffer'` for raw Buffer object, or `'json'` for automatic JSON.parse result. Default `'buffer'`.
140162

141163
### 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-
150164
```javascript
151165
key.sign(buffer, [encoding], [source_encoding]);
152166
```
@@ -161,44 +175,21 @@ Return result of check, `true` or `false`.<br/>
161175
**source_encoding** - same as for `encrypt` method.<br/>
162176
**signature_encoding** - encoding of given signature. May be `'buffer'`, `'binary'`, `'hex'` or `'base64'`. Default `'buffer'`.
163177

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 = new NodeRSA.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-
191178
## Contributing
192179

193180
Questions, comments, bug reports, and pull requests are all welcome.
194181

195182
## Changelog
196183

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.
202193

203194
### 0.1.54
204195
* Added support for loading PEM key from Buffer (`fs.readFileSync()` output)

gruntfile.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
module.exports = function(grunt) {
1+
module.exports = function (grunt) {
22
grunt.initConfig({
33
jshint: {
4-
options: {
5-
},
4+
options: {},
65
default: {
76
files: {
8-
src: ['src/**/*.js', '!src/libs/**/*']
7+
src: ['gruntfile.js', 'src/**/*.js', '!src/libs/jsbn.js']
98
}
109
},
1110
libs: {
@@ -19,17 +18,16 @@ module.exports = function(grunt) {
1918
options: {
2019
reporter: 'List'
2120
},
22-
all: { src: ['test/**/*.js'] }
21+
all: {src: ['test/**/*.js']}
2322
}
2423
});
2524

2625
require('jit-grunt')(grunt, {
2726
'simplemocha': 'grunt-simple-mocha'
2827
});
2928

30-
3129
grunt.registerTask('lint', ['jshint:default']);
3230
grunt.registerTask('test', ['simplemocha']);
3331

3432
grunt.registerTask('default', ['lint', 'test']);
35-
}
33+
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-rsa",
3-
"version": "0.1.54",
3+
"version": "0.2.0",
44
"description": "Node.js RSA library",
55
"main": "src/NodeRSA.js",
66
"scripts": {
@@ -18,7 +18,10 @@
1818
"encryption",
1919
"decryption",
2020
"sign",
21-
"verify"
21+
"verify",
22+
"pkcs1",
23+
"oaep",
24+
"pss"
2225
],
2326
"author": "rzcoder",
2427
"license": "BSD",

0 commit comments

Comments
 (0)