Simple encryptiondecryption method package, including encode (), decode (), MD5 ()

zhaozj2021-02-11  200

package steeven; / * Purpose: Simple encryption / decryption methods of packaging: steeven@kali.com.cn Date: 12/05/2001 thanks: http://www-900.ibm.com/developerWorks/java/l-security /INDEX.SHTML Description: this class nesed jce, download here: http://java.sun.com/security/index.html*/; import javax.crypto. *; public class crypt {private Static string algorithm = "des"; // Defines the encryption algorithm, available DES, DESEDE, BLOWFISH Static Boolean Debug = false; static {security.addprovider (new com.sun.crypto.provider.sunjce ());} // Generate Key, pay attention to this step time Commercial Static Byte [] getKey () throws exception {keygenerator keygen = keygenerator.getinstance (algorithm); secretkey design = keygen.generateKey = keygen.generateKey (); if (debug) system.out.println (" Generate a key: " Byte2hex (deskey.getencoded ())))); return deskey.getencoded ();} // encryption public static botty [] encode (byte [] inford, byte [] key) throwy = New javax.crypto.spec.secretKeyspec (key, algorithm); if (debug) {system.out.println ("Two-in-bits before encryption:" Byte2HEX (Input)); system.out.println ("Before encryption Word String: " new string (input));} Cipher C1 = Cipher.GetInstance (Algorithm); c1.init (cipher.encrypt_mode, deskey); byte [] cipherbyte = c1.dofinal (Input); if (debug) System.out.println ("Encrypted Bit:" Byte2Hex (Cipherbyte)); Return Cipherbyte;} // Decryption Public Static Byte [] Decode (Byte [] Input, Byte [] Key) THROWS EXCEPTION {SECRETKEY Deskey = new javax.crypto.spec.secretKeyspec (key, algorithm); if (debug) System.out.println ("Information before Decryption:" Byte2HEX (Input)); Cipher C1 = Cipher.GetInstance (Algorithm); C1.INIT (Cipher.Decrypt_mode, deskey); Byte [] Clearbyte = C1.DOFINAL (INPUT);

转载请注明原文地址:https://www.9cbs.com/read-5841.html

New Post(0)