Closed Dindaleon closed 8 years ago
Wrap your bytes in a forge buffer:
decipher.update(forge.util.createBuffer(somedataBytes));
@dlongley great! That fixed it.
Another question, in this issue (https://github.com/digitalbazaar/forge/issues/135) you say to use at most 16 bytes for the IV. Could you please elaborate more on this? Can the key size be 32 bytes and the IV size only 16? Right now, I am setting both to 32.
@Dindaleon,
The IV size needs to match the block size for the cipher, not the key size. AES uses a 16 byte block size and hence a 16 byte IV. It doesn't matter what the key size is, the IV is always 16 bytes. AES-128 uses a 16 byte key and 16 byte IV, AES-192 uses a 24 byte key and a 16 byte IV, AES-256 uses a 32 byte key and a 16 byte IV.
If you provide an IV of 32 bytes, the last 16 bytes will be ignored. So just use 16 bytes so there won't be any confusion.
Perfect! Thank you.
Thank you so much sir @dlongley :+1:
Wrap your bytes in a forge buffer:
decipher.update(forge.util.createBuffer(somedataBytes));
I don't know how to thank you!!! It worked!
Hello,
I need to save the key and iv in a database for later use. Both are generated the following way: var secret = forge.random.getBytesSync(32); var iv = forge.random.getBytesSync(32);
The problem is that if I save them just like that, and then retrieve them, they get corrupted. So, what is the proper way for storing and retrieving those values?
EDIT I am saving them like this:
Then, when I need to decipher, I convert them back to bytes like this:
This gives me the following error: