Password algorithm class written in Java

xiaoxiao2021-03-06  46

Package data;

Import java.security. *; import javax.crypto. *; import javax.crypto.spec. *; import java.io. *;

/ ** * Security provides a security algorithm class, including symmetric cryptographic algorithm and hash algorithm * / public final class security {/ ** * symmetric encryption method * @Param Bytesource needs encrypted data * @return passes encrypted data * @throws Exception * / public static byte [] symmetricEncrypto (byte [] byteSource) throws Exception {ByteArrayOutputStream baos = new ByteArrayOutputStream (); try {int mode = Cipher.ENCRYPT_MODE; SecretKeyFactory keyFactory = SecretKeyFactory.getInstance ( "DES"); Byte [] keydata = {1, 9, 8, 2, 0, 8, 2, 1}; deskeyspec keySpec = new deskeyspec (keydata); key key = keyfactory.generateSecret (keySpec); cipher copher = copher.getinstance (" "); Cipher.init (Mode, key); int blocksize = copher.getblocksize (); int position = 0; intlene = bytesource.length; boolean more = true; while (more) {ix (position blocksize < = Length) {baos.write (cipher.update (bytesize); position = blocksize;} else {more = false;}}}}} f (position

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

New Post(0)