Cryptographic test diverging from class execution

Asked

Viewed 73 times

3

I made my class in java for encryption using AES. However I went to test it on this site here: http://aesencryption.net/

Java class:
text: test
key: abcdefghijklmno1
outworking: 5brjBUDRtK7OzHLZf/Pv9a==

however the result of the site was different: 9rHpDdonevdWy+1PnTSweA==

public String encrypt(String Data, String pKey) throws Exception
  {
    Key key = generateKey(pKey);
    Cipher c = Cipher.getInstance(ALGO);
    c.init(Cipher.ENCRYPT_MODE, key);
    byte[] encVal = c.doFinal(Data.getBytes("UTF-8"));
    return new BASE64Encoder().encode(encVal);
  }

The doubt is as follows which of the 2 encryptions is correct?

  • And look how cool, if I take the java class that they provide this is the result tLVGNiaoZ1YQA68tNS8C4w==. It’s all crazy, rsrs.

  • Can make your method available generateKey()? And also the String ALGO.

  • private Key generateKey(String pKey) throws Exception
 {
 Key key = new SecretKeySpec(pKey.getBytes("UTF-8"), "AES");
 return key;
 }

  • private Static final String SOMETHING = "AES";

  • Thanks @Gustavocinque managed to solve XD.

1 answer

3


I decided to change the following line:

Cipher c = Cipher.getInstance("AES/ECB/NoPadding");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.