Files
core_ng/@sammo/crypto/src/PBKDF2.ts
T
Hide_D e59f9a9659 monorepo 버전 준비
## @strpc
기존 RPC를 package화

### @strpc/express
express의 middleware + router 결함

## @sammo
게임 전체
- server, client
- gateway_server, gateway_client
2023-09-23 16:29:18 +00:00

48 lines
956 B
TypeScript

const subtle = globalThis.crypto.subtle;
export type ValidEncAlg = 'AES256-GCM' | 'AES128-GCM' | 'AES256-CBC' | 'AES128-CBC';
const encAlgMap: Record<ValidEncAlg, AesDerivedKeyParams> = {
'AES256-GCM': {
name: 'AES-GCM',
length: 256,
},
'AES128-GCM' : {
name: 'AES-GCM',
length: 128,
},
'AES256-CBC' : {
name: 'AES-CBC',
length: 256,
},
'AES128-CBC' : {
name: 'AES-CBC',
length: 128,
},
}
export async function PBKDF2_SHA512(password: string, salt: BufferSource, alg: ValidEncAlg = 'AES256-GCM', iterations = 600000): Promise<CryptoKey> {
const param: Pbkdf2Params = {
name: 'PBKDF2',
hash: 'SHA-512',
salt: salt,
iterations,
};
const encoder = new TextEncoder();
const baseKey = await subtle.importKey(
"raw",
encoder.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
);
return await subtle.deriveKey(
param,
baseKey,
encAlgMap[alg],
true,
["encrypt", "decrypt"]
);
}