Encryption Keys
const encryptionKey: string = '0101010101010101010101010101010101010101010101010101010101010101';Example: Create and store encryption key to local storage
// hash-service.ts
import { pbkdf2 } from '@railgun-community/wallet';
import { Pbkdf2Response } from '@railgun-community/shared-models';
export const hashPasswordString = async ({ secret, salt, iterations }): Promise<Pbkdf2Response> => {
return pbkdf2(secret, salt, iterations);
},import { getRandomBytes } from '@railgun-community/wallet';
import { hashPasswordString } from './hash-service';
export const setEncryptionKeyFromPassword = async (password: string): Promise<string> => {
// Desired `password` comes from user input
const salt = getRandomBytes(16); // Generate salt
const [encryptionKey, hashPasswordStored] = await Promise.all([
hashPasswordString(password, salt, 100000), // Generate hash from password and salt
hashPasswordString(password, salt, 1000000), // Generate hash for stored password. Use more iterations for the stored value.
]);
await Promise.all([
..., // Save `hashPasswordStored` to local storage
..., // Save `salt` to local storage
]);
return encryptionKey;
};Example: Get encryption key from local storage
Last updated