The process of implementing asymmetric encryption algorithm in java

1. What is symmetric encryption and asymmetric encryption?

Symmetric encryption: The decryption method is the inverse of the encryption method, that is, the same key (primary encryption algorithm) is used for encryption and decryption.

Asymmetric encryption: Encryption and decryption require two keys, the public key and the private key (higher encryption algorithm).

2. The main implementation of symmetric encryption and asymmetric encryption

The main implementation of symmetric encryption:

1) DES (Data EncrypTIon Standard): Poor security, generally not recommended.

2) 3DES: Triple DES, for the problem of short DES key length, 3DES can achieve a minimum of 112 bits and a maximum 168-bit key length.

3) AES: Better security than 3DES.

4) PBE (Password Based EncrypTIon): Password-based encryption, combining the advantages of DES and AES.

The main implementation of asymmetric encryption:

1) DH (Diffie-Hellman): Key exchange algorithm.

2) RSA: based on factorization.

3) ElGamal: Based on discrete logarithms.

4) ECC (EllipTIcal Curve Cryptography): Elliptic curve encryption.

3. Implementation of symmetric encryption in JAVA (PBE encryption):

[java] view plain copypublic class PBE {

Private staTIc String src=“security with PBE”;

Public static void main(String[] args){

jdkPBE();

}

Public static void jdkPBE(){

Try {

/ / Initialize the salt (scrambling code)

SecureRandom random=new SecureRandom();

Byte[] salt=random.generateSeed(8);

/ / password and key

String password=“CSDN”;

PBEKeySpec pbeKeySpec=new PBEKeySpec(password.toCharArray());

SecretKeyFactory factory=SecretKeyFactory.getInstance("PBEWITHMD5andEDS");

Key key=factory.generateSecret(pbeKeySpec);

//encryption

PBEParameterSpec pbeParameterSpec=new PBEParameterSpec(salt,100);//Parameter 1. Salt, parameter 2. Number of iterations

Cipher cipher=Cipher.getInstance("PBEWITHMD5andEDS");

Cipher.init(Cipher.ENCRYPT_MODE,key,pbeParameterSpec);

Byte[] result=cipher.doFinal(src.getBytes());

System.out.println("jdk pbe encrypt:" + Base64.encodeToString(result,1));

//decrypt

Cipher.init(Cipher.DECRYPT_MODE,key,pbeParameterSpec);

Result=cipher.doFinal(result);

System.out.println("jdk pbe decrypt:"+new String(result));

} catch (Exception e) {

e.printStackTrace();

}

}

}

Digital Signage For Bank

Digital Signage For Bank,Signage Screen,Digital Signage Advertising,Smart Digital Signage

Guangdong Elieken Electronic Technology Co.,Ltd. , https://www.elieken.com

Posted on