我正在使用本机浏览器加密 API 生成公钥和私钥,如下所示:
export const generateKeyPair = async (): Promise<CryptoKeyPair> => {
return await window.crypto.subtle.generateKey(
{
name: "ECDH",
namedCurve: "P-384",
},
true,
["deriveKey", "deriveBits"],
);
};
然后我将publicKey
使用下面的exportKey
函数导出window.crypto.subtle
:
const keyPair: CryptoKeyPair = yield generateKeyPair();
const publicKeyArrayBuffer: ArrayBuffer = yield window.crypto.subtle.exportKey("raw", keyPair.publicKey);
const publicKeyAsBase64 = arrayBufferToBase64(publicKeyArrayBuffer);
如果您有任何建议,请告诉我并帮助我解决此问题。