One: Basic Concepts
Plaintext: information to be encrypted
Ciphertext: The encrypted plaintext
Encryption: The process of converting plaintext to ciphertext
Encryption algorithm: conversion algorithm for converting plaintext to ciphertext
Encryption key: the key used for encryption operations through encryption algorithms
Decryption: The process of converting ciphertext to plaintext
Decryption Algorithm: Algorithm for converting ciphertext to plaintext
Decryption key: the key used for decryption operations through the decryption algorithm
Cryptanalysis: The process of inferring the original plaintext or key by analyzing the intercepted ciphertext in the view of the interceptor
Active attack: the attacker illegally invades the password system, and uses forgery, modification, deletion, etc. to inject fake news into the system to deceive
Passive attack: intercept the ciphertext and analyze and attack it against a secure system (no damage to the ciphertext)
Cryptosystem: It consists of five parts: plaintext space, ciphertext space, key space, encryption algorithm and decryption algorithm
Two: password classification
1): Sort by time
Classical cipher: using characters as the basic encryption unit
Modern ciphers: the basic unit of encryption is the block of information
2): According to the cryptographic system
name | alias | Detailed description |
Symmetric cipher | Single key cipher or private key cipher | means the encryption key is the same as the decryption key |
asymmetric cipher | Dual-key cryptography or public-key cryptography | It means that the encryption key is different from the decryption key, and the key is divided into a public key and a private key |
Symmetric Cryptographic Algorithms | Single-key cryptography or private-key cryptography | Refers to encryption and decryption algorithms applied to symmetric ciphers |
Asymmetric cryptographic algorithm | Two-drug cryptography or public key cryptography | Refers to encryption and decryption algorithms applied to asymmetric ciphers |
3): divided according to the method of plaintext processing
Block cipher: When encrypting the value, the plaintext is divided into fixed-length groups, and each block is encrypted with the same key and algorithm, and the output is also a fixed-length ciphertext, which is mostly used for network encryption.
Stream cipher: also known as sequence cipher, which refers to each encrypted bit or one byte of plaintext during encryption
Three: Hash function
1): The hash function is used to verify the integrity of the data
2): Features: unlimited length, easy calculation of hash value, irreversible hash operation process
3): Related algorithm:
Message Digest Algorithm MD5, SHA--Secure Hash Algorithm
Four: digital signature
Mainly for processing messages stored in digital form
Five: Implement the Base64 algorithm
1): Definition
Encoding algorithm based on 64 characters
2): Algorithm implementation
-jdk
-Comoons Codec
-Bouncy Castle
3) Code implementation
import org.apache.commons.codec.binary.Base64; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; import java.io.IOException; /** * Base64 encryption algorithm */ public class Base64Util { private static String src="Use Base64 encryption algorithm"; // use jdk public static void jdkBase64() throws IOException{ //encryption System.out.println("====使用jdk====="); BASE64Encoder encoder=new BASE64Encoder(); String encodeSrc=encoder.encode(src.getBytes()); System.out.println("The encrypted ciphertext is: "+encodeSrc); // decrypt BASE64Decoder decoder=new BASE64Decoder(); String decoderSrc=new String(decoder.decodeBuffer(encodeSrc)); System.out.println("The decrypted plaintext is: "+decoderSrc); } // use Comoons Codec public static void ComoonsCodecBase64(){ System.out.println("===使用Commons codec==="); //encryption byte[] encodeSrc= Base64.encodeBase64(src.getBytes()); System.out.println("Encrypted ciphertext: "+new String(encodeSrc)); // decrypt byte[] decodeSrc= Base64.decodeBase64(encodeSrc); System.out.println("Decrypted plaintext: "+new String(decodeSrc)); } // use Bouncy castle public static void BouncyCastleBase64(){ System.out.println("===使用Bouncy Castle==="); //encryption byte[] encodeSrc= org.bouncycastle.util.encoders.Base64.encode(src.getBytes()); System.out.println("Encrypted ciphertext: "+new String(encodeSrc)); // decrypt byte[] decodeSrc= org.bouncycastle.util.encoders.Base64.decode(new String(encodeSrc)); System.out.println("Decrypted ciphertext: "+new String(decodeSrc)); } public static void main(String[] args){ try { jdkBase64(); ComoonsCodecBase64(); BouncyCastleBase64(); }catch (IOException e){ e.printStackTrace (); } } }
Six: Application scenarios of Base64 algorithm
e-mail, key, certificate files