Comments (10)
@cadorn -- I added CFB mode support and examples for using it. Let me know if there are any issues.
from forge.
@cadorn, while I was at it, I added CFB, OFB, and CTR cipher modes.
from forge.
@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
from forge.
Given:
key: 861009ec4d599fab1f40abc76e6f89880cff5833c79c548c99f9045f191cd90b
iv: d927ad81199aa7dcadfdb4e47b6dc694
data: MY-DATA-AND-HERE-IS-MORE-DATA
After encryption I get:
80eb666a9fc9e263faf71e87ffc94451d7d8df7cfcf2606470351dd5ac3f70bd
While my existing JS implementation (cifre) and PHP implementation give me:
80eb666a9fc9e263faf71e87ffc94451d7d8df7cfcf2606470351dd5ac
Notice the extra 3f70bd
at the end of the forge result.
If I decrypt the forge result with cifre I get:
MY-DATA-AND-HERE-IS-MORE-DATA
When I decrypt result from cifre with forge I get:
MY-DATA-AND-HERE
Any idea what the extra characters at the end are and how they can be removed from the forge result?
from forge.
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:
encrypted: 80eb666a9fc9e263faf71e87ffc94451d7d8df7cfcf2606470351dd5ac3f70bd
decrypted: MY-DATA-AND-HERE-IS-MORE-DATA
What are the differences with your code?
from forge.
Wow. Thanks for the quick addition.
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.
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
Yes.
from forge.
@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.
from forge.
@cadorn, it looks like I need to change the default padding for CFB (none) -- let me look into that.
from forge.
@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.
from forge.
Great. Thanks!
from forge.
Related Issues (20)
- Only 8, 16, 24, or 32 bits supported: 248 HOT 4
- Support for AES-CMAC
- Support different MAC Algorithms to generate PKCS12 wrapper HOT 1
- Add support for SubjectKeyIdentifier in CMS message (PKCS#7) HOT 1
- Add support for RSASSA-PSS as scheme to sign CMS message (PKCS#7)
- Add support for pkcs encryption with secret key for recipient
- node-forge AES-GCM fails to decrypt from .NET core 5.0 HOT 1
- forge/prime.worker.js 404 (Not Found)
- Bug in signcms code
- how can add AIA data to cert?
- Cannot read X.509 certificate. ASN.1 object is not an X509v3 Certificate
- PKCS12 File Password with ISO-8859-9 Encoding
- Can't create a CSR with extKeyUsage extension HOT 1
- Invalid RSAES-OAEP padding WHY
- Inconsistent Key Generation using seed value HOT 6
- License Clarification
- TypeError: i.randomBytes is not a function
- When creating self-signed certificate how can I add subjectAltName HOT 1
- [jsbn] Node 21 introduced `navigator` global object which has changed jsbn behaviour
- node:crypto to node-forge HMAC convertion HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from forge.