Classification of encryption algorithms:
1. symmetric encryption DES, AES
2. asymmetric encryption RSA, DSA,
3. One-way encryption MD5, Sha
Features of symmetric encryption:
1. Both parties use the same key. The decryption party must know the encryption key in advance.
2. What key is used for encryption? The same key must be used for decryption.
3. Different keys are used for the same information, and the encryption results are theoretically different.
In Des, a 56-bit key is used and the attached 8 is the parity bit. The maximum 64-bit grouping size is greatly increased. Attack des. Generally, you can only use the exhaustive key to search, that is, repeat various keys until there is a matching one.
3DES, namely, Triple DES, is an enhanced version of DES and a safer deformation of DES. It uses three 56-bit keys to encrypt data three times. Generally, provides strong security.
Encryption steps:
1. Specify the provider of the secret Algorithm
Security. addprovider (new COM. Sun. crypto. provider. sunjce ());
2. instantiate a key generator
Keygenerator keygen = keygenerator. getinstance ("desede ");
3. Generate a key
Secretkey secret ey = keygen. generatekey ();
4. Define a cipher object and use it for encryption and decryption.
Cipher c = cipher. getinstance ("desede ");
5. initialize the cipher object, specifying the key, encryption/Decryption Mode
C. INIT (Cipher. encrypt_mode, cipher ey );
6. the plaintext needs to be converted into byte streams for encryption.
Byte [] src = msg. getbytes ();
Byte [] ENC = C. dofinal ();
7. Output encryption information. Convert byte Transfer to string result = string (ENC );
Asymmetric confidential:
In the process of asymmetric encryption algorithm, the receiver generates a public key and a private key. The former is public, and the sender processes the plaintext with the public key of the receiver, which is converted into meters for sending, after receiving the ciphertext, the receiver uses its own private key to heap the ciphertext for decryption and restores it to plain text.
The encryption and decryption processes are almost similar to DES, but a pair of keys are generated when the key is generated. The public key is used for encryption and the private key is used for decryption.
Keypairgenerator keypairgen = keypairgenerator. getinstance ("RSA ");
Keypairgen. initizlize (1024 );
Keypair = keypairgen. generatekeypair ();
Rsw.vatekey privatekey = (rsw.vatekey) keypair. getprivate ();
Rsapublickey publickey = (rsapublickey) keypair. getpublic ();
Features of one-way encryption algorithms:
1. the encryption algorithm executes this function repeatedly for the same message to get the same definition.
2. the ciphertext generated by the encryption algorithm is unpredictable. The ciphertext seems to have nothing to do with the plaintext.
3. Any slight change in plaintext will have a great impact on the generated ciphertext.
4. irreversible
Steps:
1. Generate the messagedigest object based on the MD5 algorithm.
2. Update the summary
3. Complete hash calculation. The result is displayed.
Sha encryption is the same as MD5 encryption.