Before I encrypted my data I've put it into this format:
let a = new TextEncoder().encode(JSON.stringify(data))
After encryption, I've encoded it for storing that way:
let b = new Uint8Array(a)
and finally converted it into base64.
Now I want to decrypt my data with sjcl library function sjcl.decrypt.
privateKey as JSON string.cipher as
Uint8Array.cipher into it's original codec after
encryption with: new TextDecoder().decode(cipher)What now? sjcl throws, json decode: this isn't json!.
Understood, because my encrypted data is an ArrayBuffer.
So my question: is it possible to decrypt my case with sjcl? When looking into sjcl source it seems, that decrypt needs a JSON. But I have no JSON.
Edit the encryption process is not possible.
Thank you!
------------ UPDATE ------------
That's how the keyPair is generated:
await window.crypto.subtle.generateKey({
name: "RSA-OAEP",
modulusLength: 2048,
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
hash: { name: "SHA-256" },
}, true, ["encrypt", "decrypt"]);
Then the key is exported like that (I receive that key):
await window.crypto.subtle.exportKey(
"jwk",
keyPair.privateKey
);
Ecryption with public key:
await window.crypto.subtle.encrypt({ name: "RSA-OAEP" }, publicKey, data);
In my application I have no access to WebCrypto Api.
Tried out sjcl library, but it seems rsa encryptio/decryption is not possible.
Tested with jsrsasign library, but it does not support jwk exported keys.
Can I convert jwk to pkcs8?