Coder Social home page Coder Social logo

Comments (4)

database64128 avatar database64128 commented on May 3, 2024 1

len(12345678901234567890123456789012) = 32

This is not a key. The key should be a slice of 32 bytes, not a string of 32 characters.

from crypto2.

database64128 avatar database64128 commented on May 3, 2024

Your key length is not 32 bytes.

from crypto2.

tfzxyinhao avatar tfzxyinhao commented on May 3, 2024

len(12345678901234567890123456789012) = 32

from crypto2.

zonyitoo avatar zonyitoo commented on May 3, 2024

The correctness is already tested with these testcases:

#[test]
fn test_aes128() {
// AES 128
let key = hex::decode("000102030405060708090a0b0c0d0e0f").unwrap();
let plaintext = hex::decode("00112233445566778899aabbccddeeff").unwrap();
let cipher = Aes128::new(&key);
let mut ciphertext = plaintext.clone();
cipher.encrypt(&mut ciphertext);
assert_eq!(
&ciphertext[..],
&hex::decode("69c4e0d86a7b0430d8cdb78070b4c55a").unwrap()[..]
);
let mut cleartext = ciphertext.clone();
cipher.decrypt(&mut cleartext);
assert_eq!(&cleartext[..], &plaintext[..]);
}
#[test]
fn test_aes192() {
let key = hex::decode("000102030405060708090a0b0c0d0e0f1011121314151617").unwrap();
let plaintext = hex::decode("00112233445566778899aabbccddeeff").unwrap();
let cipher = Aes192::new(&key);
let mut ciphertext = plaintext.clone();
cipher.encrypt(&mut ciphertext);
assert_eq!(
&ciphertext[..],
&hex::decode("dda97ca4864cdfe06eaf70a0ec0d7191").unwrap()[..]
);
let mut cleartext = ciphertext.clone();
cipher.decrypt(&mut cleartext);
assert_eq!(&cleartext[..], &plaintext[..]);
}
#[test]
fn test_aes256() {
// AES 256
let key =
hex::decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f").unwrap();
let plaintext = hex::decode("00112233445566778899aabbccddeeff").unwrap();
let cipher = Aes256::new(&key);
let mut ciphertext = plaintext.clone();
cipher.encrypt(&mut ciphertext);
assert_eq!(
&ciphertext[..],
&hex::decode("8ea2b7ca516745bfeafc49904b496089").unwrap()[..]
);
let mut cleartext = ciphertext.clone();
cipher.decrypt(&mut cleartext);
assert_eq!(&cleartext[..], &plaintext[..]);
}

AES is a symmetric cipher algorithm, which means that the cipher text's length should be identical with the text. Your Java output:

James
u9QmnI+gjMUK9LETbm2eWA==

should have included some kind of padding, because it is exactly 16bytes length (128-bits), which is AES's block length.

A little bit of searching shows that:

For Oracle JDK 7 (tested), the default cipher for AES is AES/ECB/PKCS5Padding. The Java Security documentation doesn't mention about this though (http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#algspec), have to do some JUnit testing to find out.

from crypto2.

Related Issues (18)

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.