-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cfb
mode for AES
#61
Comments
@cadorn -- I added CFB mode support and examples for using it. Let me know if there are any issues. |
@cadorn, while I was at it, I added CFB, OFB, and CTR cipher modes. |
@dlongley Wow. Thanks for the quick addition. Is the AES encryption/decryption in CFB mode compatible with the following?: AES (Rijndael- 128) in CFB mode with a 32 byte key size, 16 byte block size, 16 byte feedback size |
Given:
After encryption I get:
While my existing JS implementation (cifre) and PHP implementation give me:
Notice the extra If I decrypt the forge result with cifre I get:
When I decrypt result from cifre with forge I get:
Any idea what the extra characters at the end are and how they can be removed from the forge result? |
It sounds like you're having trouble with the padding. There may or may not be a bug in forge related to this, but the padding shouldn't be affected by the cipher block mode (correction, the default padding should not be affected but stream mode shouldn't be using it). Here's some code below that seems to be working just fine for me: var key = '861009ec4d599fab1f40abc76e6f89880cff5833c79c548c99f9045f191cd90b';
var iv = 'd927ad81199aa7dcadfdb4e47b6dc694';
var data = 'MY-DATA-AND-HERE-IS-MORE-DATA';
key = forge.util.hexToBytes(key);
iv = forge.util.hexToBytes(iv);
var cipher = forge.aes.createEncryptionCipher(key, 'CFB');
cipher.start(iv);
cipher.update(forge.util.createBuffer(data));
cipher.finish();
var encrypted = cipher.output;
console.log('encrypted: ' + encrypted.toHex());
cipher = forge.aes.createDecryptionCipher(key, 'CFB');
cipher.start(iv);
cipher.update(encrypted);
cipher.finish();
var decrypted = cipher.output.getBytes();
console.log('decrypted: ' + decrypted);
assert.equal(data, decrypted); The above code prints this for me:
What are the differences with your code? |
Sure! It wasn't too difficult to add ... and I had been meaning to for quite a while so I figured that since someone else needed it I'd see if it could be done quickly.
Yes. |
@cadorn, it looks like the cifre and PHP code you're using is not padding the output; you should always get multiples of the block size and that output is only 29 bytes long (58 in hex) when it should be 32. |
@cadorn, it looks like I need to change the default padding for CFB (none) -- let me look into that. |
@cadorn, padding should have been turned off for any cipher stream modes (the new ones just added) with automatic truncation rather than default PKCS#7 padding. This has been corrected in the latest commit. |
Great. Thanks! |
Are there plans to implement
cfb
mode for AES?I am trying to move to forge exclusively and am missing this.
Currently using: https://github.com/openpeer/cifre/blob/master/aes.js (which has a bug with data > 15 chars)
The text was updated successfully, but these errors were encountered: