@stratumn/js-crypto
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -25,2 +25,4 @@ 'use strict'; | ||
this.encrypt = function (message) { | ||
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8'; | ||
var iv = _nodeForge.random.getBytesSync(SALT_LENGTH); | ||
@@ -32,3 +34,3 @@ var ci = _nodeForge.cipher.createCipher('AES-GCM', _this._key); | ||
ci.start({ iv: iv, tagLength: TAG_LENGTH * 8 }); | ||
ci.update(_nodeForge.util.createBuffer(message)); | ||
ci.update(_nodeForge.util.createBuffer(message, encoding)); | ||
ci.finish(); | ||
@@ -41,2 +43,4 @@ | ||
this.decrypt = function (ciphertext) { | ||
var encoding = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'utf8'; | ||
if (ciphertext.length <= SALT_LENGTH + TAG_LENGTH) { | ||
@@ -56,3 +60,3 @@ throw new Error('wrong ciphertext format'); | ||
} | ||
return de.output.data; | ||
return encoding === 'binary' ? Buffer.from(de.output.data, 'binary') : de.output.toString(encoding); | ||
}; | ||
@@ -71,2 +75,3 @@ | ||
Encrypts a message with the symmetric key. | ||
The encoding may be specified with the following values: 'utf8' (default), 'ascii', 'binary' | ||
It formats the encrypted message as follows: | ||
@@ -79,2 +84,5 @@ - base64(<iv><ciphertext><tag>) | ||
Decrypts a message with the symmetric key. | ||
The encoding may be specified with the following values: 'utf8' (default), 'ascii', 'binary'. | ||
Returns the decoded message as a string except if the encoding is set to | ||
'binary' (in which case the result will be a Buffer or an Uint8Array). | ||
It accepts a message formatted as follows: | ||
@@ -81,0 +89,0 @@ - base64(<iv><ciphertext><tag>) |
{ | ||
"name": "@stratumn/js-crypto", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Browser compatible crypto", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51469
1025