Is java java.security.PrivateKey thread safe? I have to verify digital singature for every request, so I was thinking, once I load the private key file from a physical location, after converting it to java.security.PrivateKey, is it okay to cache it so that I do not have to create the Private every time.
private PrivateKey privateKey;
private PrivateKey getPrivateKey(byte[] keyFileBytes) throws Exception {
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyFileBytes);
KeyFactory kf = KeyFactory.getInstance("RSA");
this.privateKey=kf.generatePrivate(spec);
}