RSA private key from PEM file and Java code converting to C#

  • Thread starter Thread starter Derderer
  • Start date Start date
D

Derderer

Guest
Hi everyone.


Can you help me, please. I stacked on one problem - I can't correctly convert Java code to C# and use the RSA private key from *.pem file.

public String sign(String message) throws SignatureException{
try {
Signature sign = Signature.getInstance("SHA1withRSA");
sign.initSign(privateKey);
sign.update(message.getBytes("UTF-8"));
return new String(Base64.encodeBase64(sign.sign()),"UTF-8");
} catch (Exception ex) {
throw new SignatureException(ex);
}
}

public boolean verify(String message, String signature) throws SignatureException{
try {
Signature sign = Signature.getInstance("SHA1withRSA");
sign.initVerify(publicKey);
sign.update(message.getBytes("UTF-8"));
return sign.verify(Base64.decodeBase64(signature.getBytes("UTF-8")));
} catch (Exception ex) {
throw new SignatureException(ex);
}
}

Continue reading...
 
Back
Top