This repository has been archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: encryption and decryption (#313)
* feat: adding encrypt and decrypt with function * feat: local storage encrypt and redux decrypt * feat: removed the encryption modal unneeded * feat: added the salt to the password * feat: removing scrypt async for diff package adding salt to localstorage
- Loading branch information
1 parent
bf0dfbf
commit 33de94d
Showing
3 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { | ||
encryptSymmetricAsStr, | ||
decryptSymmetricStr, | ||
CryptoInput, | ||
EncryptedSymmetricString, | ||
coToUInt8, | ||
} from '@kiltprotocol/sdk-js/build/crypto' | ||
import { scrypt } from 'scrypt-js' | ||
|
||
export function encryption( | ||
message: string, | ||
secret: CryptoInput | ||
): EncryptedSymmetricString { | ||
return encryptSymmetricAsStr(message, secret) | ||
} | ||
|
||
export function decryption(data: string, secret: CryptoInput): string | null { | ||
return decryptSymmetricStr(JSON.parse(data), secret) | ||
} | ||
|
||
export function passwordHashing( | ||
password: string, | ||
salt: string | ||
): Promise<Uint8Array> { | ||
const N = 1024 | ||
const r = 8 | ||
const p = 1 | ||
const dkLen = 32 | ||
return scrypt(coToUInt8(password), coToUInt8(salt), N, r, p, dkLen) | ||
} |