Allow to add context on key derivations
This commit is contained in:
+5
-5
@@ -14,19 +14,19 @@ export default class PrivateBox {
|
||||
|
||||
public static async gen(extractable: boolean = true): Promise<CryptoKeyPair> {
|
||||
log.trace('generate keypair')
|
||||
return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveKey']) as CryptoKeyPair
|
||||
return await crypto.subtle.generateKey(consts.ECDH, extractable, ['deriveBits']) as CryptoKeyPair
|
||||
}
|
||||
|
||||
public static async encrypt(data: Uint8Array, pubkey: CryptoKey): Promise<PrivateBox> {
|
||||
public static async encrypt(data: Uint8Array, pubkey: CryptoKey, context?: string): Promise<PrivateBox> {
|
||||
log.trace('encrypt')
|
||||
const tmp_pair = await PrivateBox.gen(false)
|
||||
const key = await ecdh(tmp_pair.privateKey, pubkey, DHusage.box)
|
||||
const key = await ecdh(tmp_pair.privateKey, pubkey, DHusage.box, context) // TODO : null
|
||||
const box = await SecretBox.encrypt(data, key)
|
||||
return new this(tmp_pair.publicKey, box)
|
||||
}
|
||||
public async decrypt(privkey: CryptoKey): Promise<Uint8Array | null> {
|
||||
public async decrypt(privkey: CryptoKey, context?: string): Promise<Uint8Array | null> {
|
||||
log.trace('decrypt')
|
||||
const key = await ecdh(privkey, this.pubkey, DHusage.box)
|
||||
const key = await ecdh(privkey, this.pubkey, DHusage.box, context) // TODO : null
|
||||
return await this.box.decrypt(key)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user