1

256ですが、GAEでは機能していないようです。「JavaCryptography Extension(JCE)Unlimited Strength Jurisdiction Policy Files」をダウンロードしました。local_policy.jar、US_export_policy.jarはC:\ Program Files \ Java\jdk1.6.0にあります。 _29 \ jre \ lib\securityの場所。

コードは次のとおりです。

import java.security.spec.KeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.*;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;

public class AESEncrypter {

private static final byte[] SALT = {
    (byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
    (byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
};
private static final int ITERATION_COUNT = 65536;
private static final int KEY_LENGTH = 256;
private Cipher ecipher;
private Cipher dcipher;

AESEncrypter(String passPhrase) throws Exception {
    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec spec = new PBEKeySpec(passPhrase.toCharArray(), SALT, ITERATION_COUNT, KEY_LENGTH);
    SecretKey tmp = factory.generateSecret(spec);
    SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");

    ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    ecipher.init(Cipher.ENCRYPT_MODE, secret);

    dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    byte[] iv = ecipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();
    dcipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
}

public String encrypt(String encrypt) throws Exception {
    byte[] bytes = encrypt.getBytes("UTF8");
    byte[] encrypted = encrypt(bytes);
    return new Base64().encodeBase64String(encrypted);
}

public byte[] encrypt(byte[] plain) throws Exception {
    return ecipher.doFinal(plain);
}

public String decrypt(String encrypt) throws Exception {
    byte[] bytes = new Base64().decodeBase64(encrypt);
    byte[] decrypted = decrypt(bytes);
    return new String(decrypted, "UTF8");
}

public byte[] decrypt(byte[] encrypt) throws Exception {
    return dcipher.doFinal(encrypt);
}

public static void main(String[] args) throws Exception {

    String message = "MESSAGE";
    String password = "PASSWORD";

    AESEncrypter encrypter = new AESEncrypter(password);
    String encrypted = encrypter.encrypt(message);
    String decrypted = encrypter.decrypt(encrypted);

    System.out.println("Encrypt(\"" + message + "\", \"" + password + "\") = \"" + encrypted + "\"");
    System.out.println("Decrypt(\"" + encrypted + "\", \"" + password + "\") = \"" + decrypted + "\"");
}

}

助けていただければ幸いですありがとう!

4

1 に答える 1

1

あなたの例外は間違いなく無制限の強さの管轄ファイルを逃すことによって引き起こされます。

これらはJava6JDKにダウンロードおよび保存されているとのことです。lib/securityJREインストールのフォルダー(ある場合)にもコピーを保存していることを確認します。

javaアプリケーションの実行時に呼び出されるコマンドを正確に把握してください。

于 2012-10-11T07:19:55.350 に答える