以下は、署名の生成に関する私のコードのスニペットです。
File file = new File("privatekey.pkcs8");
FileInputStream fis = new FileInputStream(file);
pemBytes = new byte[fis.available()];
fis.read(pemBytes);
fis.close();
File filedata = new File("hi");
FileInputStream fis2 = new FileInputStream(filedata);
dataBytes = new byte[fis2.available()];
fis2.read(dataBytes);
fis2.close();
} catch (Exception e) {
e.printStackTrace();
}
PrivateKey privKey=null;
try {
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
privKey = kf.generatePrivate(keySpec);
} catch (Exception e) {
e.printStackTrace();
}
/* Create a Signature object and initialize it with the private key */
byte[] realSig = null;
try{
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initSign(privKey);
signature.update(dataBytes);
realSig = signature.sign();
byte[] res = Base64.encodeBase64(realSig);
FileOutputStream sigfos = new FileOutputStream("mysignature");
sigfos.write(res);
sigfos.close();
} catch (Exception e) {
e.printStackTrace();
署名は正常に機能しますが、現在、署名が場合によっては 30 日後に期限切れになるタイムスタンプ機能を実装したいと考えています。ただし、タイムスタンプを扱った経験がなく、十分に説明されている例やチュートリアルも見つかりませんでした。したがって、開始方法のリンク/説明/チュートリアルをお願いしたいと思います! 可能であれば、私が使用できるコードのスニペット! 前もって感謝します!