Example of implementing DES encryption decryption in JSP

zhaozj2021-02-16  50

Examples achieve DES encryption and decryption in the JSP examples Download: Download DES.java package Lion.Security.Cryptography; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.NoSuchPaddingException; import javax.crypto. SecretKey; import java.security.nosuchalgorithmexception; import java.security.security; / ** * DES encrypted, files with two methods, encryption, decryption * @Author lion * @Author www.lionsky.net * / public class Class SLIONSKY.NET * / PUBLIC Class DES {private String Algorithm = "DES"; private KeyGenerator keygen; private SecretKey deskey; private Cipher c; private byte [] cipherByte; / ** * example DES initialization * / public DES () {init ();} public void init () {Security.addProvider (new com.sun.crypto.provider.SunJCE ()); try {keygen = KeyGenerator.getInstance (Algorithm); deskey = keygen.generateKey (); c = Cipher.getInstance (Algorithm);} Catch (nosuchalgorithmexception ex) {ex.printStackTrace ();} catch (nosuchpaddingexception ex) { EX.PrintStackTrace ();}} / ** * Encrypts the String * @Param Str To encrypt data * @return returns the encrypted BYTE array * / public byte [] CreateEncryptor (string str) {Try {C.init (Cipher.ENCRYPT_MODE, deskey); cipherByte = c.doFinal (str.getBytes ());} catch (java.security.InvalidKeyException ex) {ex.printStackTrace ();} catch (javax.crypto.BadPaddingException ex) {ex .printstacktrace ();} catch (javax.crypto.illegalblocksizeException ex) {EX.PrintStackTrace ();} Return CipherbyTe;} / ** * Decrypts the BYTE array * @Param BUFF to decrypt data * @

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

New Post(0)