Comparing version 1.0.1 to 1.0.2
@@ -12,2 +12,8 @@ ## 1.0.0 | ||
- Add keywords. | ||
- Add keywords. | ||
## 1.0.2 | ||
**2019-01-20** | ||
- Update README.md. |
{ | ||
"name": "crypto-es", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A cryptography algorithms library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -24,3 +24,3 @@ # CryptoES | ||
You can then import it as a regular ECMAScript module: | ||
Then you can import CryptoES as a regular ECMAScript module: | ||
@@ -282,3 +282,40 @@ ``` | ||
``` | ||
const JsonFormatter = { stringify: function (cipherParams) { // create json object with ciphertext const jsonObj = { ct: cipherParams.ciphertext.toString(CryptoES.enc.Base64) }; // optionally add iv and salt if (cipherParams.iv) { jsonObj.iv = cipherParams.iv.toString(); } if (cipherParams.salt) { jsonObj.s = cipherParams.salt.toString(); } // stringify json object return JSON.stringify(jsonObj); }, parse: function (jsonStr) { // parse json string const jsonObj = JSON.parse(jsonStr); // extract ciphertext from json object, and create cipher params object const cipherParams = CryptoES.lib.CipherParams.create({ ciphertext: CryptoES.enc.Base64.parse(jsonObj.ct) }); // optionally extract iv and salt if (jsonObj.iv) { cipherParams.iv = CryptoES.enc.Hex.parse(jsonObj.iv) } if (jsonObj.s) { cipherParams.salt = CryptoES.enc.Hex.parse(jsonObj.s) } return cipherParams; } }; const encrypted = CryptoES.AES.encrypt("Message", "Secret Passphrase", { format: JsonFormatter }); alert(encrypted); // {"ct":"tZ4MsEnfbcDOwqau68aOrQ==","iv":"8a8c8fd8fe33743d3638737ea4a00698","s":"ba06373c8f57179c"} const decrypted = CryptoES.AES.decrypt(encrypted, "Secret Passphrase", { format: JsonFormatter }); alert(decrypted.toString(CryptoES.enc.Utf8)); // Message | ||
const JsonFormatter = { | ||
stringify: function (cipherParams) { // create json object with ciphertext | ||
const jsonObj = { ct: cipherParams.ciphertext.toString(CryptoES.enc.Base64) }; // optionally add iv and salt | ||
if (cipherParams.iv) { | ||
jsonObj.iv = cipherParams.iv.toString(); | ||
} | ||
if (cipherParams.salt) { | ||
jsonObj.s = cipherParams.salt.toString(); | ||
} | ||
// stringify json object | ||
return JSON.stringify(jsonObj); | ||
}, | ||
parse: function (jsonStr) { // parse json string | ||
const jsonObj = JSON.parse(jsonStr); // extract ciphertext from json object, and create cipher params object | ||
const cipherParams = CryptoES.lib.CipherParams.create( | ||
{ ciphertext: CryptoES.enc.Base64.parse(jsonObj.ct) }, | ||
); // optionally extract iv and salt | ||
if (jsonObj.iv) { | ||
cipherParams.iv = CryptoES.enc.Hex.parse(jsonObj.iv) | ||
} | ||
if (jsonObj.s) { | ||
cipherParams.salt = CryptoES.enc.Hex.parse(jsonObj.s) | ||
} | ||
return cipherParams; | ||
}, | ||
}; | ||
const encrypted = CryptoES.AES.encrypt( | ||
"Message", | ||
"Secret Passphrase", | ||
{ format: JsonFormatter }, | ||
); | ||
alert(encrypted); // {"ct":"tZ4MsEnfbcDOwqau68aOrQ==","iv":"8a8c8fd8fe33743d3638737ea4a00698","s":"ba06373c8f57179c"} | ||
const decrypted = CryptoES.AES.decrypt( | ||
encrypted, | ||
"Secret Passphrase", | ||
{ format: JsonFormatter }, | ||
); | ||
alert(decrypted.toString(CryptoES.enc.Utf8)); // Message | ||
``` | ||
@@ -285,0 +322,0 @@ |
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
165138
372