UNPKG

@wisiendot/expo-unlimited-secure-store

Version:

An 'unlimited' secure store engine for expo projects, also compatible with redux-persist. (Expo's SecureStore was limited to 2KB in SDK v33)

25 lines (19 loc) 667 B
import CryptoJS from 'crypto-js'; export const encryptWithRandomKey = (data) => { const encryptionKey = generateKey(256); const encryptedData = CryptoJS.AES.encrypt(data, encryptionKey).toString(); return { encryptionKey, encryptedData }; }; export const decrypt = (data, key) => { const decryptedBytes = CryptoJS.AES.decrypt(data, key); const decryptedValue = decryptedBytes.toString(CryptoJS.enc.Utf8); return decryptedValue; }; const generateKey = (length) => { let key = ''; const hex = '0123456789abcdef'; for (i = 0; i < length; i++) { key += hex.charAt(Math.floor(Math.random() * 16)); } return key; };