Giter VIP home page Giter VIP logo

Comments (10)

dlongley avatar dlongley commented on July 20, 2024

@cadorn -- I added CFB mode support and examples for using it. Let me know if there are any issues.

from forge.

dlongley avatar dlongley commented on July 20, 2024

@cadorn, while I was at it, I added CFB, OFB, and CTR cipher modes.

from forge.

cadorn avatar cadorn commented on July 20, 2024

@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.

cadorn avatar cadorn commented on July 20, 2024

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.

dlongley avatar dlongley commented on July 20, 2024

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.

dlongley avatar dlongley commented on July 20, 2024

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.

dlongley avatar dlongley commented on July 20, 2024

@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.

dlongley avatar dlongley commented on July 20, 2024

@cadorn, it looks like I need to change the default padding for CFB (none) -- let me look into that.

from forge.

dlongley avatar dlongley commented on July 20, 2024

@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.

cadorn avatar cadorn commented on July 20, 2024

Great. Thanks!

from forge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.