Java平台安全与杂项功能详解
1. 数字签名
数字签名结合了消息摘要算法和公钥加密技术。发送方(如Alice)计算消息的摘要,然后用她的私钥对摘要进行加密。接收方(如Bob)使用发送方的公钥解密摘要,验证消息是否被篡改,同时确认消息来自发送方。
1.1 创建数字签名步骤
- 获取私钥 :假设系统中存在密钥库,可通过以下代码获取私钥:
// Here is some basic data we need
File homedir = new File(System.getProperty("user.home"));
File keyfile = new File(homedir, ".keystore"); // Or read from config file
String filepass = "KeyStore password"; // Password for entire file
String signer = "david"; // Read from config file
String password = "No one can guess this!"; // Better to prompt for this
PrivateKey key; // This is the key we want to look up from the keystore
try {
// Obtain a KeyStore object and then l
超级会员免费看
订阅专栏 解锁全文
284

被折叠的 条评论
为什么被折叠?



