mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-11 19:40:47 +01:00
use rsaExtractPublicKey for getting public key
This commit is contained in:
parent
2bc7ae0da2
commit
269b59210c
@ -146,7 +146,7 @@ export class CryptoService implements CryptoServiceAbstraction {
|
||||
return null;
|
||||
}
|
||||
|
||||
this.publicKey = null; // TODO:
|
||||
this.publicKey = await this.cryptoFunctionService.rsaExtractPublicKey(privateKey);
|
||||
return this.publicKey;
|
||||
}
|
||||
|
||||
|
@ -133,14 +133,15 @@ export class NodeCryptoFunctionService implements CryptoFunctionService {
|
||||
return Promise.resolve(this.toArrayBuffer(decipher));
|
||||
}
|
||||
|
||||
async rsaExtractPublicKey(privateKey: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
rsaExtractPublicKey(privateKey: ArrayBuffer): Promise<ArrayBuffer> {
|
||||
const privateKeyByteString = Utils.fromBufferToByteString(privateKey);
|
||||
const privateKeyAsn1 = forge.asn1.fromDer(privateKeyByteString);
|
||||
const forgePrivateKey = (forge as any).pki.privateKeyFromAsn1(privateKeyAsn1);
|
||||
const forgePublicKey = (forge.pki as any).setRsaPublicKey(forgePrivateKey.n, forgePrivateKey.e);
|
||||
const publicKeyAsn1 = (forge.pki as any).publicKeyToAsn1(forgePublicKey);
|
||||
const publicKeyByteString = forge.asn1.toDer(publicKeyAsn1).data;
|
||||
return Utils.fromByteStringToArray(publicKeyByteString).buffer;
|
||||
const publicKeyArray = Utils.fromByteStringToArray(publicKeyByteString);
|
||||
return Promise.resolve(publicKeyArray.buffer);
|
||||
}
|
||||
|
||||
randomBytes(length: number): Promise<ArrayBuffer> {
|
||||
|
Loading…
Reference in New Issue
Block a user