Package com.example.decript;
Import java.io.UnsupportedEncodingException;
Import java.security.InvalidKeyException;
Import Java.security.MessageDigest;
Import java.security.NoSuchAlgorithmException;
Import Java.security.SecureRandom;
Import javax.crypto.BadPaddingException;
Import Javax.crypto.Cipher;
Import javax.crypto.IllegalBlockSizeException;
Import Javax.crypto.KeyGenerator;
Import javax.crypto.NoSuchPaddingException;
Import Javax.crypto.SecretKey;
Import Javax.crypto.spec.SecretKeySpec; public class Decripttest {public static string SHA1 (String decript) {try {messagedigest digest = java.security.m
Essagedigest. getinstance ("SHA-1");
Digest.update (Decript.getbytes ());
byte messagedigest[] = Digest.digest ();
Create Hex String StringBuffer hexstring = new StringBuffer (); The byte array is converted to a hexadecimal number for (int i = 0; i < messagedigest.length; i++) {String Shahex = integer.tohexstring (Messagedi
Gest[i] & 0xFF);
if (Shahex.length () < 2) { Hexstring.append (0);
} hexstring.append (Shahex);
return hexstring.tostring ();
catch (NoSuchAlgorithmException e) {e.printstacktrace ();
Return ""; public static string SHA (String decript) {try {messagedigest digest = java.security.MessageDigest. Getinst
ance ("SHA");
Digest.update (Decript.getbytes ());
byte messagedigest[] = Digest.digest ();
Create Hex String StringBuffer hexstring = new StringBuffer (); The byte array is converted to a hexadecimal number for (int i = 0; i < messagedigest.length; i++) {String Shahex = integer.tohexstring (Messagedi
Gest[i] & 0xFF);
if (Shahex.length () < 2) {hexstring.append (0);
} hexstring.append (Shahex);
return hexstring.tostring ();
catch (NoSuchAlgorithmException e) {e.printstacktrace ();
Return ""; public static string MD5 (String input) {try {//Get MD5 Digest algorithm MessageDigest object messagedigest mdinst = Messagedi
Gest.getinstance ("MD5"); Update summary m with the specified byteDinst.update (Input.getbytes ());
Get ciphertext byte[] MD = Mdinst.digest ();
Converts cipher text into a string form of 16 StringBuffer hexstring = new StringBuffer ();
byte array to hexadecimal number for (int i = 0; i < md.length i++) {String Shahex = integer.tohexstring (Md[i] & 0xFF);
if (Shahex.length () < 2) {hexstring.append (0);
} hexstring.append (Shahex);
return hexstring.tostring ();
catch (NoSuchAlgorithmException e) {e.printstacktrace ();
Return ""; /** * Encryption * @param content * @param password * Encryption password * @return/PU Blic static byte[] Encryptaes (string content, string password) {try {keygenerator KGen = keygenerator.getinstance ("
AES ");
Kgen.init (128, New SecureRandom (Password.getbytes ()));
Secretkey Secretkey = Kgen.generatekey ();
byte[] Encodeformat = secretkey.getencoded ();
Secretkeyspec key = new Secretkeyspec (Encodeformat, "AES"); Cipher Cipher = cipher.getinstance ("AES");Create cipher byte[] bytecontent = content.getbytes ("Utf-8");
Cipher.init (Cipher.encrypt_mode, key);//Initialize byte[] result = cipher.dofinal (bytecontent); return result;
Encryption} catch (NoSuchAlgorithmException e) {e.printstacktrace ();
catch (Nosuchpaddingexception e) {e.printstacktrace ();
catch (InvalidKeyException e) {e.printstacktrace ();
catch (Unsupportedencodingexception e) {e.printstacktrace ();
catch (Illegalblocksizeexception e) {e.printstacktrace ();
catch (Badpaddingexception e) {e.printstacktrace ();
return null; /** * Decrypt * @param content * @param password * Decryption key * @return/Publ IC Static byte[] Decryptaes (byte[] content, String password) {try {keygenerator KGen = keygenerator.getinstance ("AE
S ");
Kgen.init (128, New SecureRandom (Password.getbytes ()));
Secretkey Secretkey = Kgen.generatekey ();
byte[] Encodeformat = secretkey.getencoded (); Secretkeyspec key = new Secretkeyspec (Encodeformat, "AES"); Cipher Cipher = cipher.getinstance ("AES");//Create cipher Cipher.init (Cipher.decrypt_mode, key);//Initialize byte[] result = Ciph
Er.dofinal (content); return result;
Encryption} catch (NoSuchAlgorithmException e) {e.printstacktrace ();
catch (Nosuchpaddingexception e) {e.printstacktrace ();
catch (InvalidKeyException e) {e.printstacktrace ();
catch (Illegalblocksizeexception e) {e.printstacktrace ();
catch (Badpaddingexception e) {e.printstacktrace ();
return null; /** * BASE64 Decryption * * @param key * @return * @throws Exception/public static string decryptBASE64 (String
Key) {return ""; /** * BASE64 Encryption * * @param key * @return * @throws Exception/public static string encryptBASE64 (String
Key) {return "";
}
}