我有以下加密数据的程序.
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
public class Test {
private static final String ALGORITHM = "AES";
private static final byte[] keyValue = "ADBSJHJS12547896".getBytes();
public static void main(String args[]) throws Exception {
String encriptValue = encrypt("dude5");
decrypt(encriptValue);
}
/**
* @param args
* @throws Exception
*/
public static String encrypt(String valueToEnc) throws Exception {
Key key = generateKey();
Cipher c = Cipher.getInstance(ALGORITHM);
c.init(Cipher.ENCRYPT_MODE, key);
System.out.println("valueToEnc.getBytes().length "+valueToEnc.getBytes().length);
byte[] encValue = c.doFinal(valueToEnc.getBytes());
System.out.println("encValue length" + encValue.length);
byte[] encryptedByteValue = …Run Code Online (Sandbox Code Playgroud) 我当时希望加密PHP服务器和Java客户端之间的数据.单独的代码工作正常,我想在PHP服务器上坚持使用OpenSSL.
当你在尝试解码PHP加密字符串时遇到错误时,你们中的任何人都会看到我在这里丢失的任何内容:
[删除非工作代码]
更新 - 我能够使用openssl.这是使用PHP和Java文件的GIT repo.