java 加密后的密文:iP6nVfCE9Eiw47utJDR6wV6Lhl4xyOgYykub0HUJSZQ=以下是 java 的 aes 加密类,希望密类,希望密类,希望密类,希望密类,希望密类,希望胜莽田umur com.mk.api.util;import java.security.Key;import java.security.MessageDigest;import java.util.Arrays;import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;import javax.xml.bind.DatatypeConverter;/***Penyulitan AES*/kelas awam AES { String akhir statik peribadi AESTYPE = " AES"; KUNCI rentetan akhir statik peribadi = "Z8LSq0wWwB5v+6YJzurcP463H3F12iZh74fDj4S74oUH4EONkiKb2FmiWUbtFh97GG/c/lbDE47mvw6j94yXxKHOpoqu6zpLKMVKPcbOzpLKMVKPcbOo LmLL2UyydtFKuU9Sa5VgY/CzGaVGJABK2ZR94="; /*** Penyulitan * @param kandungan * @return*/ public static String encrypt(String str) { try { Key key = generateKey(); Cipher c = Cipher.getInstance(AESTYPE); c.init(Cipher.ENCRYPT_MODE, kunci); byte[] encVal = c.doFinal(str.getBytes()); String encryptedValue = DatatypeConverter.printBase64Binary(encVal); pulangkan encryptedValue; } tangkapan (Pengecualian e) { e.printStackTrace(); } kembali null; } /*** Penyahsulitan * kandungan @param * @kembali*/ public static String decrypt(String str) { try { Key key = generateKey(); Cipher c = Cipher.getInstance(AESTYPE); c.init(Cipher.DECRYPT_MODE, kunci); byte[] decordedValue = DatatypeConverter.parseBase64Binary(str); byte[] decValue = c.doFinal(decordedValue); String decryptedValue = new String(decValue); pulangkan decryptedValue; } tangkapan (Pengecualian e) { e.printStackTrace(); } kembali null; } private static Key generateKey() membuang Exception { bait[] keyValue = KEY.getBytes("UTF-8"); MessageDigest sha = MessageDigest.getInstance("SHA-1"); keyValue = sha.digest(keyValue); keyValue = Arrays.copyOf(keyValue, 16); Kunci kekunci = SecretKeySpec baharu(Nilai kunci, AESTYPE); kunci pulangan; } }
Lihat ini: //m.sbmmt.com/php-weizijiaocheng-455991.html
Format kod di atas bercelaru