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发行说明。
Now that you have generated a signature for some data, you need to save the signature bytes in one file and the public key bytes in another so you can send (via modem, floppy, mail, and so on) someone else现在您已经为某些数据生成了签名,您需要将签名字节保存在一个文件中,将公钥字节保存在另一个文件,以便您可以(通过调制解调器、软盘、邮件等)发送给其他人
The receiver can verify that the data came from you and was not modified in transit by running the 接收器可以通过运行您在即将到来的验证数字签名步骤中生成的VerSig
program you will generate in the upcoming Verifying a Digital Signature steps. That program uses the public key to verify that the signature received is the true signature for the data received.VerSig
程序来验证数据是否来自您,并且在传输过程中没有被修改。该程序使用公钥来验证接收到的签名是否是接收到的数据的真实签名。
Recall that the signature was placed in a byte array named 回想一下,签名被放置在一个名为realSig
. You can save the signature bytes in a file named sig
via the following.realSig
的字节数组中。您可以通过以下方式将签名字节保存在名为sig
的文件中。
/* save the signature in a file */ FileOutputStream sigfos = new FileOutputStream("sig"); sigfos.write(realSig); sigfos.close();
Recall from the Generate Public and Private Keys step that the public key was placed in a PublicKey object named 回想一下,在生成公钥和私钥步骤中,公钥被放置在名为pub
. pub
的公钥对象中。You can get the encoded key bytes by calling the 您可以通过调用getEncoded方法来获取编码的密钥字节,然后将编码的字节存储在文件中。你可以随意命名文件。getEncoded
method and then store the encoded bytes in a file. You can name the file whatever you want. If, for example, your name is Susan, you might name it something like 例如,如果你的名字是Susan,你可以将其命名为suepk
(for "Sue's public key"), as in the following:suepk
(意为“Sue's公钥”),如下所示:
/* save the public key in a file */ byte[] key = pub.getEncoded(); FileOutputStream keyfos = new FileOutputStream("suepk"); keyfos.write(key); keyfos.close();