C# Equivalent code of Java

  • Thread starter Thread starter Jeetendra Khandelwal
  • Start date Start date
J

Jeetendra Khandelwal

Guest
Hi!

I'm unable to convert the Java encryption code to C#.

package com.avenues.lib.utility;

import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.spec.X509EncodedKeySpec;

import javax.crypto.Cipher;

import android.util.Base64;


public class RSAUtility {
public static String encrypt(String plainText, String key){
try{
PublicKey publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(key, Base64.DEFAULT)));
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
return Base64.encodeToString(cipher.doFinal(plainText.getBytes("UTF-8")),Base64.DEFAULT);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

Continue reading...
 
Back
Top