- Common ways to obtain RSAPrivateKey
private void myMethod () {RSAPrivateKey r =
KeyFactory keyFactory;KeySpec keySpec;(RSAPrivateKey) keyFactory.generatePrivate(keySpec)
KeyPair keyPair;(RSAPrivateKey) keyPair.getPrivate()
Qute.libg.cryptography.RSA rSA;BigInteger modulus;BigInteger privateExponent;rSA.create(new RSAPrivateKeySpec(modulus, privateExponent))
- Smart code suggestions by Codota
}
/** * Sign a message and base64 encode the signature. */ public String sign(String msg) { try { RSAPrivateKey key = getPrivateKey(); Signature sig = Signature.getInstance(SIGNING_ALGORITHM + "with" + key.getAlgorithm()); sig.initSign(key); sig.update(msg.getBytes("UTF-8")); return hudson.remoting.Base64.encode(sig.sign()); } catch (GeneralSecurityException e) { throw new SecurityException(e); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); // UTF-8 is mandatory } }
/** * Sign a message and base64 encode the signature. */ public String sign(String msg) { try { RSAPrivateKey key = getPrivateKey(); Signature sig = Signature.getInstance(SIGNING_ALGORITHM + "with" + key.getAlgorithm()); sig.initSign(key); sig.update(msg.getBytes("UTF-8")); return hudson.remoting.Base64.encode(sig.sign()); } catch (GeneralSecurityException e) { throw new SecurityException(e); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); // UTF-8 is mandatory } }