Below is a snippet of my code on generating signature:
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();
the signature works fine but currently I would like to implement a time stamp function which will cause the signature to expire after sometimes, perhaps 30 days. However, I have no experience dealing with time stamp, I was also unable to find example or tutorials which explain well enough. Therefore, I would like to ask for links/explanation/tutorial on how to get started! And if possible, snippet of codes that I could use! Thanks in advance!