Digital signatures are often used to verify software and software makers to ensure that the software code is not in any way.
Tarnish.
Alternatively, using digital signatures to ensure software "cleaning" and "authentic", that is, software
From its manufacturer or publisher until the end user has not been tampered with others during this time.
This article gives a simple review of the relevant concepts of digital signatures, given Java to create and use
Digital signature specific method.
First, digital signature and its function
Digital Signing Algorithm (DSA) is one of the "Public Key Cardiode Algorithm", so let us
"Private Key / Public Keys" begins to make a simple review.
1. Private key encryption and limitations
Private Key Encryption System encrypts and decrypts using unique keys (ie, private keys). This key
The sender and the recipient must be shared. That is, if the armor is to be encrypted by it, the one needs to use a key.
Encrypt information; after the acceptance of the message, you must use the same key to decrypt information.
This method obviously has a very serious disadvantage. For example, the received parties must have the same key, this
Seeking must have a safe protocol to ensure the reliability of key transfer; second, there is an urgent encryption message
When you want to send, you may not complete the transfer due to no keys of the recipient; third, if you want to send the news to a lot
Different groups need to correspond to each group, maintain many different keys.
In order to overcome the weaknesses of the private key encryption system, people introduced the public key encryption system.
2. Public key encryption
Public key encryption does not require a sender and recipient of a message to know the other party's key, you can access
This encryption information.
The public key encryption system uses a key pair (public key and private key) to encrypt and decrypt information.
Its encryption is also very simple: information encrypted with public key can only be unwave with the private key corresponding to it;
Information with private key encrypted, anyone who has a per capita with the corresponding public key can be unbearable. Therefore, private
There is always a personal storage without having to pass it, and the public key can be authorized to use others without destroying security.
There will always be one-to-one relationship between sex, public key and private key. Specifically,
First, if the information is encrypted with the public key of the recipient, only those who should receive this message
Can decrypt it (ie, only people who have a private key corresponding to the public key can be decrypted). E.g,
The armor is to send an encrypted email from B, and the armor must be encrypted with the public key of B.
Second, if the information is encrypted by the sender's private key, any of the officials of the sender
The recipient can decrypt information to determine that the information is indeed from the sender, and information
The content has not been disrupted by any unintentional or malicious destruction.
The second point described above is the meaning of digital signature.
3. Digital signature features
A digital signature is a fixed length binary digital stream, which is attached to the signed data.
It can be used with any type of digital data, except for the most ordinary code software. Can also be used in passwords,
Email and electronic documentation. The main functions of digital signatures are: preventing the original document from being contaminated or changed;
Prevent don't use your heart to use others name to spread fraudulent news; and who is the certificate of document author
According to, wait.
Second, create and use digital signatures with Java
In addition to the features mentioned above, there is a more realistic meaning of digital signatures with Java. The most common is:
Applying digital signatures can break through some of the browser's security in security. For example, your browser is general
Will reject the online Java program read and write the files of your local hard drive or get your local information (such as your user)
Name, etc.), even if you confirm that the Java program is "reliable" (in fact you can't fully confirm
A program is really "reliable"). If you have to run the Java program, you must close your browsing
Safety inspection function of the unit, but this is tantamount to set the local system as "no fire in the city." Use a digital sign
The name can be perfectly solved this problem: When the browser "feel" is used to you, after the signature Java applet,
It automatically searches for the matching digital signature and checks, if successful, the browser determines the Java applet.
It is "trust", so I am released. In this way, it is guaranteed that security, but also allows the true "trusted" Java program to have many privileges (see the Java program).
In JDK1.1, the work related to digital signatures is done by the tool program javakey.
Javakey is a command line tool provided by Sun to generate a number of archive files (JAR files).
Word signature and manage the key database.
Below we will take a specific example to see the steps to create and use digital signatures,
The concept and explanation will be given in the example.
1. Creation of Java Programs and Digital Signatures (Steps to Encrypted or Signed)
The following Java applet is very simple, its main function is: get the current login of Win95 / 98 system
The user's name string, then writes it to the Test.txt file of the current directory of the local hard drive.
Import java.awt. *;
Import java.io. *;
Import java.lang. *;
Import java.applet. *;
Public class myapp extends applet {
DataOutputStream out_file;
Public void paint (graphics g) {
Try {
String YourName = System.getProperty ("User.Name");
OUT_FILE = New DataOutputStream (New FileoutputStream ("Test.txt"));
OUT_FILE.WRITECHARS ("Your name:" YourName "/ N");
OUT_FILE.CLOSE ();
g.drawstring ("Your Name Has Been Written to File
}
Catch (IOException E) {
g.drawstring ("File I / O Error", 12, 12);
}
Catch (securityException se) {
g.drawstring ("You CAN Not Write to Disk or Get User Name.", 12, 12);
}
}
}
// end of myapp.java
After compiling myapp.java into myapp.class, send it to your browser with myApp.html below.
(The command is appletViewer myApp.html).
applet>
Here's the Source .
/ * End of myapp.html * / We discovers that "You CAN NOT WRITE to DISK or Get User Name" is displayed on your browser.
This is because the username and write local hard drive are prohibited by the system security feature.
Below we create a digital signature so that the user's user does not need to change the security check of your browser.
Features can complete the program function (ie: read username, write files).
Step 1: Create an entity and set it to "trusted".
Javakey -CS Kompass True
The entity here refers to the signator (individual, company or organization), which is assumed to "kompass". Participate
The number "-cs" tells Javakey to create a signator and put it into the database (without parameters run Javakey)
Detailed help information will be obtained). Optional parameter "true" means signing "Kompass" is "
"(The default is" untrusted ").
Step 2: Generate a key pair (public key and private key) and output to file (optional).
Javakey -GK Kompass DSA 512 KOMPASS_PUB KOMPAMPASS_PRIV
Where "DSA" is the name of the encryption algorithm, "512" is the length of the key, "Kompass_Pub",
"Kompass_Priv" is the name of the two key output files, respectively.
Step 3: Generate a license (CERTIFICATE).
Javakey -gc certificate_directive_kompass
The license here is a digital signature that can be handed over to the recipient.
The above parameter "CERT_DIRECTIVE_KOMPAMPAMPAMPASS" is not an output file name, but a default
Parameter configuration file name. Popularly, it is like a ".ini" file, Javakey according to the file
Content decisions how to generate a license. Therefore, the signator must be edited with text before performing this step.
Mr. Mr. This configuration file (learning the name indicating file - Directive file).
The following is given the contents of the file CERT_DIRECTIVE_KOMPAMPAMPass:
Issuer.name = kompass
Issuer.cert = 1
SUBJECT.NAME = kompass
Subject.real.name = kompass
Subject.org.Unit = javasoft
Subject.org = Sun Microsystems
Subject.country = US
Start.date = 31 May 1999
End.date = 30 May 2012
Serial.Number = 1001
Out.File = kompass.key
/ * End of cort_directive_kompass * /
As can be seen from the last line of the above, the name of the output file is defined as "kompass.key", namely:
Digital signature "kompass.key" will be sent together to the recipient with the signature file.
Other information included in the above documents mainly: issuer information (ISSUER), theme information
(Subject), license information (expiration date and serial number), etc.
Step 4: Create an archive file (JAR file).
Jar cf signmyapp.jar myapp.class myapp.html
What is needed here is that JAR is another command line tool provided by Sun for generating and maintenance.
Archive file (.jar file). JAR is a packaging tool that packed a Java applet along with a file, an image, an animation, and other files into a file to facilitate the release and transmission of Java products. versus
Winzip and other tools, JAR can also compress files when packaging. Detailed information about JAR
See the relevant information on Sun.
The function of the above command is to package the file "myapp.class" with "myapp.html" as an archive file.
Signmyapp.jar.
The reason for this step is required because Javake can only sign the archive file.
Step 5: Signing the archive file.
Javakey -gs sign_directive_kompass signalmyapp.jar
Like the third step above, "sIGN_DIRECTIVE_KOMPAMPAMPASS" is also a configuration file (indication
File), used to tell Javake how to sign the file. "SIGN_DIRECTIVE_KOMPAMPASS"
The content is as follows:
Signer = kompass
CERT = 1
CHAIN = 0
Signature.file = kpssig
/ * End of sign_directive_kompass * /
Step 6: Change the file name.
Ren signmyapp.jar.sig signmyapp.jar
We noticed that the output file name is not specified in the fifth step in the fifth step. Javakey in this case
Add ".sig" as the output file name after the name of the signed file.
To specify the output file, join the line in "Sign_Directive_KOMPAMPASS":
Out.file = signmyapp.jar
At this point, we have completed the job of digital signatures. "Kompass.Key" and
"Signmyapp.jar" (filed after signature) is passed to the user.
2. Use of digital signatures (steps to decrypt or users should perform)
Step 1: Get a license (ie digital signature - kompass.key) and files after signature.
Step 2: Create a signature entity and set it to "trusted".
Javakey -c Kompass True
Step 3: Pour the license into the database.
Javakey -ic Kompass Kompass.Key
The last step: Run the Java program.
AppletViewer signmyapp.html
We noticed that ".html" here is not "MyApp.html" given above. In fact, these two
The difference is small, "signmyapp.html" just a parameter:
Archive = "signmyapp.jar"
It tells the browser all useful files (here myapp.class) all in the archive file
In other places.
The content of SignmyApp.html is as follows:
applet>
Here's the Source .
/ * End of signmyapp.html * /
Now, we finally saw the long-awaited results: browser played "Your Name HAS
Been Written to File
Its content is the name of the user log in to WIN95 / 98:
Y o U r n a m E: m a w e n q i a n
create function dddlr (@fzr int) returns int asbegin declare @pfzr int declare @res int select @ pfzr = (select dlrbh from dlxx where wtrbh = @ fzr) if @pfzr is null select @ res = @fzr else select @ res = DBO.DDDLR (@pfzr) return @resend