有没有任何示例Java代码与AES网站完全一样的AES加密? [英] Is there any sample Java code that does AES encryption exactly like this website?

查看:97
本文介绍了有没有任何示例Java代码与AES网站完全一样的AES加密?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.hanewin.net/encrypt/aes/aes- test.htm

如果您访问此网站并输入以下内容:

If you go to this website and enter the following:

"Key In Hex":        00000000000000000000000000123456

"Plain Text in Hex": 00000000000000000000000000000000

然后点击加密按钮,你会看到十六进制的密文是:

And click on "Encrypt" button you will see the ciphertext in hex is:

3fa9f2a6e4c2b440fb6f676076a8ba04

是否有一个Java程序,我可以做到这一点(即是否有一个AES库,输入上面的键入十六进制中的十六进制纯文本,并生成十六进制文件中的密文)?

Is there a Java program out there that I can do this (I.e. Is there an AES library that will input the "Key In Hex" above with the "Plain Text In Hex" above and generate the Ciphertext in Hex above? )?

感谢任何建议或链接Java示例代码,这样做。

I would appreciate any advice or links to Java sample code that does this.

推荐答案

请参阅下面的代码以使用JCE类进行此操作的标准方法。

See the code below for the standard way to do this with JCE classes.

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;

public class EncryptionExample {

  public static void main(String[] args) throws Exception {
    final String keyHex = "00000000000000000000000000123456";
    final String plaintextHex = "00000000000000000000000000000000";

    SecretKey key = new SecretKeySpec(DatatypeConverter
        .parseHexBinary(keyHex), "AES");

    Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
    cipher.init(Cipher.ENCRYPT_MODE, key);

    byte[] result = cipher.doFinal(DatatypeConverter
        .parseHexBinary(plaintextHex));

    System.out.println(DatatypeConverter.printHexBinary(result));
  }
}

打印:

3FA9F2A6E4C2B440FB6F676076A8BA04

这篇关于有没有任何示例Java代码与AES网站完全一样的AES加密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆