The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
The 您即将创建的GenSig
program you are about to create will use the JDK Security API to generate keys and a digital signature for data using the private key and to export the public key and the signature to files. The application gets the data file name from the command line.GenSig
程序将使用JDKSecurity API为使用私钥的数据生成密钥和数字签名,并将公钥和签名导出到文件中。应用程序从命令行获取数据文件名。
The following steps create the 以下步骤创建GenSig
sample program.GenSig
示例程序。
Prepare Initial Program Structure准备初始程序结构
Create a text file named 创建一个名为GenSigjava的文本文件。键入初始程序结构(导入语句、类名、GenSig.java
. Type in the initial program structure (import statements, class name, main
method, and so on).main
方法等)。
Generate Public and Private Keys生成公钥和私钥
Generate a key pair (public key and private key). The private key is needed for signing the data. The public key will be used by the 生成密钥对(公钥和私钥)。签名数据需要私钥。公钥将由VerSig
program for verifying the signature.VerSig
程序用于验证签名。
Get a 获取Signature
object and initialize it for signing. Supply it with the data to be signed, and generate the signature.Signature
对象并初始化它以进行签名。向其提供要签名的数据,并生成签名。
Save the Signature and the Public Key in Files将签名和公钥保存在文件中
Save the signature bytes in one file and the public key bytes in another.将签名字节保存在一个文件中,将公钥字节保存在另一个文件。