I'm trying to decrypt a string using SubtleCrypto that was pre-generated.
Instead of getting decrypted text I'm getting the error: Failed to execute 'decrypt' on 'SubtleCrypto': parameter 2 is not of type 'CryptoKey'.
console.log(window.crypto.subtle.decrypt({name:"AES-CBC", iv:""}, "1234567890123456", "i4+WxNH8XYMnAm7RsRkfOw=="));
I've tried researching the error but haven't come across anything related to such a basic example. What am I doing wrong?
The parameters have the wrong types: IV and data must be passed as
BufferSource, the key asCryptoKey, seeSubtleCrypto.decrypt(). ACryptoKeyis returned bySubtleCrypto.importKey(), which is used to import the key.WebCrypto API (as low level API) does not provide support for data conversion, e.g. Base64 encoded data or strings to
BufferSource, so other helper methods must be used for this.The following code decrypts the ciphertext: