⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 desalgorithm.java

📁 200多个自己编的java程序,大家可以学一下.
💻 JAVA
字号:
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;


public class DESAlgorithm {

    private static String algorithm = "DESede";


    public static SecretKey genDESKey(byte[] keyByte) throws Exception {
        SecretKey key = new SecretKeySpec(keyByte, algorithm);
        return key;
    }


    public static byte[] desEncrypt(SecretKey key, String crypt)
            throws Exception {
        return desEncrypt(key, crypt.getBytes());
    }


    public static byte[] desEncrypt(SecretKey key, byte[] crypt)
            throws Exception {
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return cipher.doFinal(crypt);
    }


    public static byte[] desDecrypt(SecretKey key, String crypt)
            throws Exception {
        return desDecrypt(key, crypt.getBytes());
    }


    public static byte[] desDecrypt(SecretKey key, byte[] crypt)
            throws Exception {
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.DECRYPT_MODE, key);
        return cipher.doFinal(crypt);
    }


    public static String getAlgorithm() {
        return algorithm;
    }


    public static void setAlgorithm(String algorithm) {
        DESAlgorithm.algorithm = algorithm;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -