jose sanchez vargas
New member
I want to generate equivalent C# code for the following JAVA code
public PublicKey getPublicKey(String base64Publica) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(base64Publica.getBytes()));
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
return keyFactory.generatePublic(keySpec);
}
public String encrypt(String data, String publica) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA1AndMGF1Padding", "BC");
OAEPParameterSpec oaepParameterSpec = new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSpecified.DEFAULT);
cipher.init(1, this.getPublicKey(publica), oaepParameterSpec);
Encoder enc = Base64.getEncoder();
return enc.encodeToString(cipher.doFinal(data.getBytes("UTF-8")));
}
Thanks in advance.
public PublicKey getPublicKey(String base64Publica) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64.getDecoder().decode(base64Publica.getBytes()));
KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
return keyFactory.generatePublic(keySpec);
}
public String encrypt(String data, String publica) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidKeySpecException, IllegalBlockSizeException, BadPaddingException, NoSuchProviderException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
Cipher cipher = Cipher.getInstance("RSA/None/OAEPWithSHA1AndMGF1Padding", "BC");
OAEPParameterSpec oaepParameterSpec = new OAEPParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, PSpecified.DEFAULT);
cipher.init(1, this.getPublicKey(publica), oaepParameterSpec);
Encoder enc = Base64.getEncoder();
return enc.encodeToString(cipher.doFinal(data.getBytes("UTF-8")));
}
Thanks in advance.