Skip to content

Commit 246bc94

Browse files
committed
Fix readme so it can be run in one file
1 parent bef7737 commit 246bc94

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ Testing [repository](https://github.com/ghbutton/react-native-simple-crypto-test
119119
import RNSimpleCrypto from "react-native-simple-crypto";
120120

121121
// -- AES ------------------------------------------------------------- //
122-
123122
const message = "data to encrypt";
124123
const messageArrayBuffer = RNSimpleCrypto.utils.convertUtf8ToArrayBuffer(
125124
message
@@ -150,30 +149,32 @@ console.log("AES decrypt", decrypted);
150149

151150
// -- HMAC ------------------------------------------------------------ //
152151

153-
const signatureArrayBuffer = await RNSimpleCrypto.HMAC.hmac256(message, key);
152+
const keyHmac = await RNSimpleCrypto.utils.randomBytes(32);
153+
const signatureArrayBuffer = await RNSimpleCrypto.HMAC.hmac256(message, keyHmac);
154154

155-
const signatureHex = RNSimpleCrypto.utils.convertArrayBuffertoHex(
155+
const signatureHex = RNSimpleCrypto.utils.convertArrayBufferToHex(
156156
signatureArrayBuffer
157157
);
158158
console.log("HMAC signature", signatureHex);
159159

160160
// -- SHA ------------------------------------------------------------- //
161161

162162
const sha1Hash = await RNSimpleCrypto.SHA.sha1("test");
163-
console.log("SHA1 hash", hash);
163+
console.log("SHA1 hash", sha1Hash);
164164

165-
const sha256Hash = await RNSimpleCrypto.SHA.sha1("test");
165+
const sha256Hash = await RNSimpleCrypto.SHA.sha256("test");
166166
console.log("SHA256 hash", sha256Hash);
167167

168-
const sha512Hash = await RNSimpleCrypto.SHA.sha1("test");
168+
const sha512Hash = await RNSimpleCrypto.SHA.sha512("test");
169169
console.log("SHA512 hash", sha512Hash);
170170

171171
const dataToHash = await RNSimpleCrypto.utils.randomBytes(64);
172172
const sha1ArrayBuffer = await RNSimpleCrypto.SHA.sha1(dataToHash);
173-
console.log('SHA256 hash bytes', [...sha1ArrayBuffer]);
173+
console.log('SHA256 hash bytes', sha1ArrayBuffer);
174174

175175
const sha256ArrayBuffer = await RNSimpleCrypto.SHA.sha256(dataToHash);
176-
console.log('SHA256 hash bytes', [...sha256ArrayBuffer]);
176+
console.log('SHA256 hash bytes', sha256ArrayBuffer);
177+
177178

178179
// -- PBKDF2 ---------------------------------------------------------- //
179180

@@ -190,20 +191,20 @@ const passwordKey = await RNSimpleCrypto.PBKDF2.hash(
190191
hash
191192
);
192193
console.log("PBKDF2 passwordKey", passwordKey);
193-
194-
const password = messageArrayBuffer;
195-
const salt = RNSimpleCrypto.utils.randomBytes(8);
196-
const iterations = 10000;
197-
const keyInBytes = 32;
198-
const hash = "SHA256";
199-
const passwordKey = await RNSimpleCrypto.PBKDF2.hash(
200-
password,
201-
salt,
202-
iterations,
203-
keyInBytes,
204-
hash
194+
const password2 = messageArrayBuffer;
195+
const salt2 = RNSimpleCrypto.utils.randomBytes(8);
196+
const iterations2 = 10000;
197+
const keyInBytes2 = 32;
198+
const hash2 = "SHA256";
199+
200+
const passwordKey2 = await RNSimpleCrypto.PBKDF2.hash(
201+
password2,
202+
salt2,
203+
iterations2,
204+
keyInBytes2,
205+
hash2
205206
);
206-
console.log("PBKDF2 passwordKey", passwordKey);
207+
console.log("PBKDF2 passwordKey", passwordKey2);
207208

208209
// -- RSA ------------------------------------------------------------ //
209210

0 commit comments

Comments
 (0)