RSA Encryption

CinjoJoseCinjoJose USUniversity ✭✭

Hi,

Please help me to encrypt string(password) in Xamarin using RSA algorithm. I am using following code in Android native. Please help me to port this in Xamarin,

        byte[] keyBytes = Base64.decode(key.getBytes("utf-8"), Base64.DEFAULT);

        X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey publicKey = keyFactory.generatePublic(spec);

        Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] encryptedBytes = cipher.doFinal(plain.getBytes());
        encrypted = Base64.encodeToString(encryptedBytes, Base64.NO_WRAP);

Thanks...

Answers

Sign In or Register to comment.