Archived Forum Post

Index of archived forum posts

Question:

RSA with SHA256

Feb 20 '17 at 10:08

Hi all,

i need to "translate" these lines writed in java. I dont' know what functions or assembly to use :

KeyStore keystore; // key repository for keys containing signature certificate
String alias; // alias for the certificate in the key repository
String password; // password for the certificate's private key
String plaintext; // text being signed

Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign((PrivateKey) keystore.getKey(alias, password.toCharArray())); signature.update(plaintext.getBytes("UTF-8")); byte[] rsa_text= signature.sign();

If someone can help me. I discover certificates and cryto. it is so new for me.

Thanks for your help.

Eric


Answer

Here's an example:

http://www.example-code.com/java/rsa_sha256_signature_using_java_keystore.asp

If you need the RSA signature as bytes, the example creates the signature in a CkByteData object. Do the following to get the bytes:

byte[] rsa_text = binarySignature.getData();