文档

Java™ 教程-Java Tutorials 中文版
生成数字签名
Trail: Security Features in Java SE
Lesson: Generating and Verifying Signatures

生成数字签名

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.

The following steps create the GenSig sample program.

  1. 准备初始程序结构

    Create a text file named GenSig.java. Type in the initial program structure (import statements, class name, main method, and so on).

  2. 生成公钥和私钥

    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.

  3. 签名数据

    Get a Signature object and initialize it for signing. Supply it with the data to be signed, and generate the signature.

  4. 将签名和公钥保存在文件中

    Save the signature bytes in one file and the public key bytes in another.

  5. 编译并运行程序


Previous page: Generating and Verifying Signatures
Next page: Prepare Initial Program Structure