この記事では、Javaによって実装されたAES暗号化アルゴリズムについて説明します。次のように、参照のために共有してください。
import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import javax.crypto.spec.SecretKeySpec;import android.util.Base64;/** * @author vipin.cb , [email protected] <br> * Sep 27, 2013, 5:18:34 PM <br> *パッケージ: - <b> com.veebow.util </b> <br> *プロジェクト: - <b> veebow </b> * <p> */public class aescrypt {private final cipher cipher;プライベート最終SecretKeySPECキー。 Private AlgorithMParameterSpec仕様。 public static final string seed_16_character = "u1mju1m0fdouz.qz"; public aescrypt()スロー例外{// sha-256を使用してハッシュパスワードを使用し、キーメッセージジェストのために出力を128ビットにトリミングします= mesagedgest.getInstance( "sha-256"); digest.update(seed_16_character.getBytes( "utf-8")); byte [] keybytes = new byte [32]; System.ArrayCopy(digest.digest()、0、keybytes、0、keybytes.length); cipher = cipher.getInstance( "aes/cbc/pkcs7padding"); key = new SecretKeysPec(keyBytes、 "aes"); spec = getiv(); } public algorithmparameterspec getiv(){byte [] iv = {0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、0、}; IVParameterSpec IVParameterspec; IVParameterSpec = new IVParameterSpec(IV); IVParameterSpecを返す; } public String encrypt(String Plantext)スロー例外{cipher.init(cipher.encrypt_mode、key、spec); byte [] necrypted = cipher.dofinal(plantext.getBytes( "utf-8")); string encryptedText = new String(base64.Encode(ancrypted、base64.default)、 "utf-8"); encryptedTextを返します。 } public String Decrypt(String CryptedText)スロー例外{cipher.init(cipher.decrypt_mode、key、spec); byte [] bytes = base64.decode(cryptedtext、base64.default); byte [] decrypted = cipher.dofinal(bytes); string decryptedText = new String(decrypted、 "utf-8"); decryptedTextを返します。 }}
PS:暗号化と復号化に興味がある友人は、このサイトのオンラインツールを参照することもできます。
パスワードセキュリティオンライン検出:
http://tools.vevb.com/password/my_password_safe
高強度パスワードジェネレーター:
http://tools.vevb.com/password/createstrongpassword
MD5オンライン暗号化ツール:
http://tools.vevb.com/password/createmd5password
Thunder、Express、およびTornado URL暗号化/復号化ツール:
http://tools.vevb.com/password/urlrethunder
オンラインハッシュ/ハッシュアルゴリズム暗号化ツール:
http://tools.vevb.com/password/hash_encrypt
この記事がみんなのJavaプログラミングに役立つことを願っています。