Also store hash
This commit is contained in:
parent
dc41c92f6b
commit
378d080cef
@ -564,6 +564,7 @@ function objectToBytes(obj: any) {
|
|||||||
|
|
||||||
interface AsymmetricallyEncryptedData {
|
interface AsymmetricallyEncryptedData {
|
||||||
symmetricKey: JsonWebKey;
|
symmetricKey: JsonWebKey;
|
||||||
|
sha256: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function encryptSubmission(plainObj: any): Promise<CipherSubmission> {
|
async function encryptSubmission(plainObj: any): Promise<CipherSubmission> {
|
||||||
@ -583,10 +584,14 @@ async function encryptSubmission(plainObj: any): Promise<CipherSubmission> {
|
|||||||
|
|
||||||
const iv = window.crypto.getRandomValues(new Uint8Array(16));
|
const iv = window.crypto.getRandomValues(new Uint8Array(16));
|
||||||
|
|
||||||
|
const plainData = objectToBytes(plainObj);
|
||||||
|
|
||||||
const symmetricallyEncryptedData = await crypto.subtle.encrypt({
|
const symmetricallyEncryptedData = await crypto.subtle.encrypt({
|
||||||
name: "AES-CBC",
|
name: "AES-CBC",
|
||||||
iv
|
iv
|
||||||
}, symmetricKey, objectToBytes(plainObj));
|
}, symmetricKey, plainData);
|
||||||
|
|
||||||
|
const plainHash = await crypto.subtle.digest('SHA-256', plainData);
|
||||||
|
|
||||||
const asymmetricallyEncryptedSymmetricKey = await crypto.subtle.encrypt(
|
const asymmetricallyEncryptedSymmetricKey = await crypto.subtle.encrypt(
|
||||||
{
|
{
|
||||||
@ -594,7 +599,8 @@ async function encryptSubmission(plainObj: any): Promise<CipherSubmission> {
|
|||||||
},
|
},
|
||||||
publicEncryptionKey,
|
publicEncryptionKey,
|
||||||
objectToBytes(<AsymmetricallyEncryptedData>{
|
objectToBytes(<AsymmetricallyEncryptedData>{
|
||||||
symmetricKey: await crypto.subtle.exportKey('jwk', symmetricKey)
|
symmetricKey: await crypto.subtle.exportKey('jwk', symmetricKey),
|
||||||
|
sha256: bufferToBase64(plainHash)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user