S
Surendra Kandira
Guest
Hi
I want to generate equivalent C# code for the following JAVA code (Encryption Sample for Java):
public String encrypt_sample_method(){
try {
String publicEncyptionKeyEncodedDer = "your_public_key_DER_format";
String pin = "string_to_encrypt";
byte[] data = Base64.decode(publicEncyptionKeyEncodedDer, Base64.DEFAULT);
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(data);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey key = keyFactory.generatePublic(pubKeySpec);
final Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = cipher.doFinal(pin.getBytes("UTF-8"));
String encryptedPin = new String(Base64.encode(encryptedBytes, Base64.DEFAULT));
return encryptedPin;
} catch (NoSuchAlgorithmException e){
//Log.e("pinError2",e.getMessage());
} catch (InvalidKeySpecException e) {
//Log.e("pinError3","",e);
} catch (Exception e) {
//Log.e("pinError10",e.getMessage());
}
return ""; // Encryption failed
}
Thanks in advance.
Continue reading...
I want to generate equivalent C# code for the following JAVA code (Encryption Sample for Java):
public String encrypt_sample_method(){
try {
String publicEncyptionKeyEncodedDer = "your_public_key_DER_format";
String pin = "string_to_encrypt";
byte[] data = Base64.decode(publicEncyptionKeyEncodedDer, Base64.DEFAULT);
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(data);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey key = keyFactory.generatePublic(pubKeySpec);
final Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING");
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encryptedBytes = cipher.doFinal(pin.getBytes("UTF-8"));
String encryptedPin = new String(Base64.encode(encryptedBytes, Base64.DEFAULT));
return encryptedPin;
} catch (NoSuchAlgorithmException e){
//Log.e("pinError2",e.getMessage());
} catch (InvalidKeySpecException e) {
//Log.e("pinError3","",e);
} catch (Exception e) {
//Log.e("pinError10",e.getMessage());
}
return ""; // Encryption failed
}
Thanks in advance.
Continue reading...