React Native JavaScript library of crypto-js.
npm install rn-crypto-jsReact Native JavaScript Library of crypto-js.
``bash`
yarn add rn-crypto-js
| Hashing | HMAC | CIPHERS | PBKDF2 |
|-------------------------- |---------------------------------- |-------------------------- |---------------------- |
| MD5 | HMAC-MD5 | AES | PBKDF2 |
| SHA1 | HMAC-SHA1 | DES | |
| SHA256 | HMAC-SHA256 | TripleDES | |
| SHA224 | HMAC-SHA224 | RC4 | |
| SHA512 | HMAC-SHA512 | RC4Drop | |
| SHA384 | HMAC-SHA384 | RABBIT | |
| SHA3 | HMAC-SHA3 | | |
| RIPEMD160 | HMAC-RIPEMD160 | | |
#### Plain text encryption
`javascript
import CryptoJS from "rn-crypto-js";
// Encrypt
const ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();
// Decrypt
const decryptedData = CryptoJS.AES.decrypt(ciphertext, 'secret key 123').toString(CryptoJS.enc.Utf8);
console.log(decryptedData); // 'my message'
`
#### Object encryption
`javascript
import CryptoJS from "rn-crypto-js";
const data = [{id: 1}, {id: 2}]
// Encrypt
const ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();
// Decrypt
const decryptedString = CryptoJS.AES.decrypt(ciphertext, 'secret key 123').toString(CryptoJS.enc.Utf8);
const decryptedData = JSON.parse(decryptedString);
console.log(decryptedData); // [{id: 1}, {id: 2}]
`
`javascript`
const hash = CryptoJS.MD5("Message").toString();
`javascript`
const hash = CryptoJS.SHA1("Message").toString();
`javascript`
const hash = CryptoJS.SHA256("Message").toString();`$3
javascript`
const hash = CryptoJS.SHA224("Message").toString();
javascript
const hash = CryptoJS.SHA384("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA512("Message").toString();
`$3
SHA-3 is the winner of a five-year competition to select a new cryptographic hash algorithm where 64 competing designs were evaluated.
`javascript
const hash = CryptoJS.SHA3("Message").toString();
`$3
`javascript
const hash = CryptoJS.RIPEMD160("Message").toString();
`HMAC
$3
`javascript
const hash = CryptoJS.MD5("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA1("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA256("Message").toString();
`
$3
`javascript
const hash = CryptoJS.SHA224("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA384("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA512("Message").toString();
`$3
`javascript
const hash = CryptoJS.SHA3("Message").toString();
`$3
`javascript
const hash = CryptoJS.HMACRIPEMD160("Message").toString();
`Ciphers
$3
The Advanced Encryption Standard (AES) is a U.S. Federal Information Processing Standard (FIPS). It was selected after a 5-year process where 15 competing designs were evaluated.`javascript
const encrypted = CryptoJS.AES.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.AES.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`$3
DES is a previously dominant algorithm for encryption, and was published as an official Federal Information Processing Standard (FIPS). DES is now considered to be insecure due to the small key size.`javascript
const encrypted = CryptoJS.DES.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.DES.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`$3
Triple DES applies DES three times to each block to increase the key size. The algorithm is believed to be secure in this form.`javascript
const encrypted = CryptoJS.TripleDES.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.TripleDES.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`$3
RC4 is a widely-used stream cipher. It's used in popular protocols such as SSL and WEP. Although remarkable for its simplicity and speed, the algorithm's history doesn't inspire confidence in its security.`javascript
const encrypted = CryptoJS.RC4.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.RC4.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`$3
It was discovered that the first few bytes of keystream are strongly non-random and leak information about the key. We can defend against this attack by discarding the initial portion of the keystream. This modified algorithm is traditionally called RC4-Drop.`javascript
const encrypted = CryptoJS.RC4Drop.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.RC4Drop.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`$3
Rabbit is a high-performance stream cipher and a finalist in the eSTREAM Portfolio. It is one of the four designs selected after a 3 1/2-year process where 22 designs were evaluated.`javascript
const encrypted = CryptoJS.Rabbit.encrypt("Message", "5ecret").toString();
ā
const decrypted = CryptoJS.Rabbit.decrypt(encrypted, "5ecret").toString(CryptoJS.enc.Utf8);
`PBKDF2
PBKDF2 is a password-based key derivation function. In many applications of cryptography, user security is ultimately dependent on a password, and because a password usually can't be used directly as a cryptographic key, some processing is required.`javascript
const salt = CryptoJS.lib.WordArray.random(128 / 8);
const key128Bits = CryptoJS.PBKDF2("Secret Passphrase", salt, {
keySize: 128 / 32
}).toString();const key256Bits = CryptoJS.PBKDF2("Secret Passphrase", salt, {
keySize: 256 / 32
}).toString();
const key512Bits = CryptoJS.PBKDF2("Secret Passphrase", salt, {
keySize: 512 / 32
}).toString();
const key512Bits1000Iterations = CryptoJS.PBKDF2("Secret Passphrase", salt, {
keySize: 512 / 32,
iterations: 1000
}).toString();
``* If it is a small change, just fork the project and create a pull request.
* If it is major, start by opening an issue.