AES加密无法在AWS实例上运行

时间:2014-11-06 04:29:30

标签: java encryption amazon-web-services amazon-ec2 aes

我正在进行基本的AES加密,但在AWS上运行代码时遇到问题。

您可以在此处查看我使用的库:https://github.com/RNCryptor/JNCryptor/blob/master/src/main/java/org/cryptonode/jncryptor/AES256JNCryptor.java

我可以在本地计算机上完全加密/解密但是当我将完全相同的代码部署到AWS时,我得到以下异常:

java.lang.RuntimeException: org.cryptonode.jncryptor.InvalidHMACException: Incorrect HMAC value.

我的代码可以在这里找到:

public static String encryptString(String plainText, String password){
    AES256JNCryptor aes256JNCryptor = new AES256JNCryptor(10000);
    String result = null;
    try {
        byte[] cipherText = aes256JNCryptor.encryptData(plainText.getBytes(), password.toCharArray());
        result = DatatypeConverter.printHexBinary(cipherText);
    }
    catch (CryptorException e){
        throw new RuntimeException(e);
    }

    return result;
}


public static String decryptString(String cipherText, String password){
    AES256JNCryptor aes256JNCryptor = new AES256JNCryptor(10000);
    String result = null;
    try {

        byte[] ciphertextData = DatatypeConverter.parseHexBinary(cipherText);

        result = new String(aes256JNCryptor.decryptData(ciphertextData, password.toCharArray()), "UTF-8");
    }
    catch (CryptorException e){
        throw new RuntimeException(e);
    }
    catch (UnsupportedEncodingException e){
        throw new RuntimeException(e);
    }

    return result;
}

以下是运行上述代码时AWS上的值:

  

密码:   979fdd95300cd747140a75501cfdc58f73c1a8eacaec5c17dc01b464cf3ce2d2919dadebc7a14172db8a67ef0aea0a8d0eac4acfb805c0dc99b6499d61831379

     

plainText :测试
  加密文字:   030172197C203B44276E06C2C82AB080C3D4FF81FF6D67935C2987E4B713603297E416E26A8533A9178D85D7B3BA71C0B5D3EDB0295EC8B6B2CB03E0B6A1DB77429713F69D020C5D869955F2256A37CCC099800177AFCDCB49DDA9988B55576293C8592A41351041941610DC50D8336435371D01E935C380E291093D684724A09523581711E86BB07E5994C302AE8C9D885EDBB4F567C9E337882EAE80DD3B61353C30DD98BDB8488B43E682239487E05B13DBF7DCFF9D68E4606B0196670258F192C92B4E9D0BA766905915C221082CB39C

以下是我本地计算机上的值:

  

密码:   979fdd95300cd747140a75501cfdc58f73c1a8eacaec5c17dc01b464cf3ce2d2919dadebc7a14172db8a67ef0aea0a8d0eac4acfb805c0dc99b6499d61831379

     

plainText :测试
  加密文字:   03011F9438F0A68186376FA5D147429A42178ECC29844A7CAABFFE2FE70371A303D07E75BB2CD2D247F831078B2E492CACB396CD503772FF74DD54BA5EC8B0A4863FA40F9DA73C6B385D3D4ABEF2C47F1966

正如您所看到的,AWS上的加密值显着更长,这让我觉得它正在使用填充做一些疯狂的事情。有什么想法吗?

以下是我的AWS信息:

  1. JVM版本 - 1.7.0_65
  2. 操作系统名称 - Linux
  3. OS Arch - AMD 64
  4. AMI信息 - Amazon Linux AMI x86_64 HVM EBS

0 个答案:

没有答案