Summary :
In this article, I use a detailed language and a large number of pictures and complete program source to show you how in Java in the implementation of message digest, message authentication code to achieve secure communication, and the use of Java tools to generate digital certificates, and use the program to sign digital certificates, As well as the process of signing the applet with the signed mathematical certificate to break the access rights of the applet, the detailed code of all examples is given.
In this article you can learn the following knowledge:
How to communicate securely between programs
What is and how to generate a message digest
What is and how to generate a message authentication code
How to build and maintain a digital certificate library using Java tools
How to authenticate a signature to a digital certificate by using a program
How to use digital certificate to give applet signature break through Applet's access rights
Key Words :
Message digest, message authentication code, fingerprint, encryption, security, Java, digital signature, applet, digital certificate
First, basic knowledge
In the process of computer secure communication, message digest and message authentication code are used to ensure that the transmitted data has not been modified by the third party.
The message digest is the result of calculating the original data according to a certain algorithm, it mainly detects whether the original data has been modified. Message digest is different from encryption, encryption is a transformation of the original data, you can get the original data from the transformed data, and the message digest is to get some information from the raw data, it is much less than the original data, so the message digest can be considered as the fingerprint of the original data.
Example: The following procedure calculates a message digest for a string
package com.messagedigest;
import java.security.*;
public class DigestPass {
public static void main(String[] args) throws Exception{
String str="Hello,I sent to you 80 yuan.";
MessageDigest md = MessageDigest.getInstance("MD5");//常用的有MD5,SHA算法等
md.update(str.getBytes("UTF-8"));//传入原始字串
byte[] re = md.digest();//计算消息摘要放入byte数组中
//下面把消息摘要转换为字符串
String result = "";
for(int i=0;i<re.length;i++){
result += Integer.toHexString((0x000000ff&re[i])|0xffffff00).substring(6);
}
System.out.println(result);
}
}