@@ -132,7 +132,7 @@ export async function createRandomSymmetricKey(): Promise<webcrypto.CryptoKey> {
132
132
// keys are extractable.
133
133
const key = await crypto . subtle . generateKey (
134
134
{
135
- name : "AES-GCM " ,
135
+ name : "AES-CBC " ,
136
136
length : 256
137
137
} ,
138
138
true ,
@@ -158,7 +158,7 @@ export async function importSymKey(
158
158
// TODO implement this function to go back from the result of the exportSymKey function to it's native crypto key object
159
159
const jwkString = Buffer . from ( strKey , "base64" ) . toString ( "utf-8" ) ;
160
160
const jwk = JSON . parse ( jwkString ) ;
161
- const key = await crypto . subtle . importKey ( "jwk" , jwk , { name : "AES-GCM " } , true , [ "encrypt" , "decrypt" ] ) ;
161
+ const key = await crypto . subtle . importKey ( "jwk" , jwk , { name : "AES-CBC " } , true , [ "encrypt" , "decrypt" ] ) ;
162
162
return key ;
163
163
}
164
164
@@ -167,7 +167,7 @@ export async function symEncrypt(key: webcrypto.CryptoKey,data: string): Promise
167
167
// TODO implement this function to encrypt a base64 encoded message with a public key
168
168
// tip: encode the data to a uin8array with TextEncoder
169
169
const dataArray = new TextEncoder ( ) . encode ( data ) ;
170
- const encryptedData = await crypto . subtle . encrypt ( { name : "AES-GCM " } , key , dataArray ) ;
170
+ const encryptedData = await crypto . subtle . encrypt ( { name : "AES-CBC " } , key , dataArray ) ;
171
171
const encryptedBase64 = Buffer . from ( encryptedData ) . toString ( "base64" ) ;
172
172
return encryptedBase64 ;
173
173
}
@@ -178,7 +178,7 @@ export async function symDecrypt(strKey: string,encryptedData: string): Promise<
178
178
// tip: use the provided base64ToArrayBuffer function and use TextDecode to go back to a string format
179
179
const key = await importSymKey ( strKey ) ;
180
180
const encryptedArray = base64ToArrayBuffer ( encryptedData ) ;
181
- const decryptedData = await crypto . subtle . decrypt ( { name : "AES-GCM " } , key , encryptedArray ) ;
181
+ const decryptedData = await crypto . subtle . decrypt ( { name : "AES-CBC " } , key , encryptedArray ) ;
182
182
const decryptedString = new TextDecoder ( ) . decode ( decryptedData ) ;
183
183
return decryptedString ;
184
184
}
0 commit comments