theshy

博客园 首页 新随笔 联系 订阅 管理

古代密码学

替换

移位

凯撒加密

https://blog.csdn.net/jianggujin/article/details/53447099?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163989006516780265432665%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=163989006516780265432665&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2

凯撒解密

频率分析法
https://blog.csdn.net/Leon_Jinhai_Sun/article/details/108691183

现代加密

对称加密

加密和解密用的同一把钥匙
流加密 块解密

DES

Data Encryption Standard

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

class Solution {
    public static void main(String[] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
        //加密
        Cipher cipherEncrypt = Cipher.getInstance("DES");
        //DES加密 密钥必须是8位
        cipherEncrypt.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("12345678".getBytes(), "DES"));
        byte[] bytes = cipherEncrypt.doFinal("fuck".getBytes());
        //输出乱码
        System.out.println(new String(bytes));
        //单独打印每个字节 发现有负数 在ASCII表找不到对应的字符 所以乱码
        for (byte aByte : bytes) {
            System.out.println(aByte);
        }
        //用base64转码 用apache的包
        String encode = Base64.encode(bytes);
        System.out.println(encode);

        //解密
        Cipher cipherDecrypt = Cipher.getInstance("DES");
        cipherDecrypt.init(Cipher.DECRYPT_MODE, new SecretKeySpec("12345678".getBytes(), "DES"));
        byte[] decodeBytes = cipherDecrypt.doFinal(Base64.decode(encode));
        System.out.println(new String(decodeBytes));
    }
}

base64

AES

Advanced Encryption Standard

posted on 2021-12-19 21:54  tziSher  阅读(87)  评论(0编辑  收藏  举报