1. Encryption algorithm
In order to secure the message in the network communication, it is generally necessary to encrypt the message, the current encryption algorithms are as follows:
Asymmetric encryption algorithm: Also known as the public key encryption algorithm, such as RSA, DSA/DSS, the most commonly used is the RSA algorithm (algorithm disclosure, can self-Baidu know the details of the algorithm), the algorithm generates a public key, the message encrypted with the public key can only be decrypted with the private key encryption of the message can only be decrypted with the public key;
Symmetric encryption algorithm: 3DES, AES, RC4, encryption key and decryption key is the same, generally used for only the communication between the two parties know the key communication mode;
Hash algorithm: MD5, SHA1, SHA256, the hash algorithm is planned to obtain the hash value, the encryption process is irreversible, the hash value can not get the original plaintext, generally used for summary signature;
2. Digital certificate
A digital certificate is a method issued by a CA (Certificate authority) to verify identity in a network communication; about digital certificates do not make a statement here, interested in the small partners can find themselves online;
The digital certificate typically contains information such as the owner of the certificate, the certificate consumer, the certificate name, the certificate's public key, and so on.
3. Certificate generation
The certificate management tool provided with the JDK Keytool can produce a certificate with the following command:
Keytool-genkey-keyalg rsa-keysize 2048-validity 36500-alias sec_test-keypass 123456-keystore Test.keystore-storepa SS 123456-dname "CN=LOCALHOST,OU=DEP,O=CN,L=BJ,ST=BJ,C=CN"
Where the-keyalg specifies the algorithm,
-KEYSIZE Specifies the key size,
-validity Specifies the period of validity, in days,
-alias aliases
-KEYPASS specifies that the private key uses a password,
-keystore Specifies the KeyStore name,
-storepass a password for the certificate library and a password to extract the public key from it
-DNAME:CN name of the owner, usually the site name or ip+ port, such as Www.baidu.com,OU organization name o organization name L City St State or province C country code
When the above command executes, a KeyStore file is generated in the current directory, which holds the key and certificate information;
To export the public key:
Keytool-export-alias sec_test-file Test_pub_cer.cer-keystore Test.keystore-storepass 123456
In the current directory will generate a Test_pub_cer.cer certificate, including the public key information and certificate-related information;
Import the partner public key:
The communication parties assume that a and B,a issued their own certificates and public public key, b all the public key encrypted by a after sending a message to a, a can be correctly decrypted, if a to B send a message, a with a private key encryption, B can be decrypted with the public key, but here is a problem is public key is open, a sent to B message, Anyone with a public key can decrypt, cannot guarantee the security of A to B to send information, so B also needs to make its own certificate, and a to the public public key, so that A to B to send information in B's public key encryption, so B can be decrypted with the private key, and other intercepted information because no private key can not decrypt A need to import the public key of B into its own certificate library;
Keytool-import-file B.cer-keystore Test.keystore-storepass 123456
If you are prompted to trust this authentication, y, you can import it after you enter it, and then view the certificate entry in the certificate store:
Keytool-list-v-keystore Test.keystore-storepass 123456
To write a little first, the following chapter will take the HTTPS protocol as an example to explain the use process in detail.
Java Digital certificate production generation