この記事では、AES対称暗号化アルゴリズムに基づいてJavaによって実装された暗号化と復号化関数について説明します。次のように、参照のために共有してください。
パッケージcom.soufun.com; Import java.io.unsupportedencodingexception; Import java.security.invalidkeyexception; import java.security.nosuchalgorithmexception; import java.security.securerandom; import java.util. javax.crypto.illegalblocksizeexception; Import javax.crypto.keygenerator; import javax.crypto.nosuchpaddingexception; import javax.crypto.spec.secretkeyspec;/** */public class aesutil {private static final string = "aes" try {kgen = keygenerator.getInstance(AES); TODO自動生成ブロックe.printstacktrace(); securerandom(password.getBytes())); kgen.genertykey(); // cipherオブジェクトの初期化cipher.init(cipher.encrypt_mode、key); cipher.dofinal(bytecontent) acktrace(); e.printstacktrace(); andom(passwore.getBytes()); ecodeformat = secretkey.getEncoded(); ] cipher.dofinal(conters); catch(nosuchpadstrace(){e.printstacktrace();変換 * @param buf * @return */ private static string parsebyte2hexstr(byte buf []){stringbuffer sb =新しいstringbuffer(int i = 0; i ++){buf [i]&0xff); -》バイナリ変換 * @param hexstr * @return */ private static byte [] parsehexstr2byte(string hexstr){if(hexstr.length()<1){return null; vyte = new Byte [hexstr.length() ;結果[i] =(high * 16 + low); args)unsupportedencodexception {new date() str(encryptresult); Encryptresultstr) ().gettime(); out.println(end-begin)}注:Securerandomは、Safe Rendumanceのシーケンスを生成します。GETBYTES()は、シードが同じである限り、シーケンスが同じである限り、このシーケンスを復元できます。
PS:暗号化と復号化に興味がある友人は、このサイトのオンラインツールを参照することもできます。
パスワードセキュリティオンライン検出:
http://tools.vevb.com/password/my_password_safe
高強度パスワードジェネレーター:
http://tools.vevb.com/password/createstrongpassword
Thunder、Express、およびTornado URL暗号化/復号化ツール:
http://tools.vevb.com/password/urlrethunder
オンラインハッシュ/ハッシュアルゴリズム暗号化ツール:
http://tools.vevb.com/password/hash_encrypt
オンラインMD5/ハッシュ/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160暗号化ツール:
http://tools.vevb.com/password/hash_md5_sha
オンラインSHA1/SHA224/SHA256/SHA384/SHA512暗号化ツール:
http://tools.vevb.com/password/sha_encode
この記事がみんなのJavaプログラミングに役立つことを願っています。