0
public static string Encrypt(string KeyToEncrypt)
    {
        byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(KeyToEncrypt);
        Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(_Pwd, _Salt);
        //Calling another private method for Encryption
        byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
        return Convert.ToBase64String(encryptedData);
    }

    private static byte[] Encrypt(byte[] candelaData, byte[] Key, byte[] IV)
    {
        MemoryStream ms = new MemoryStream();
        CryptoStream cs = null;

            Rijndael alg = Rijndael.Create();
            alg.Key = Key;
            alg.IV = IV;
            cs = new CryptoStream(ms, alg.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(candelaData, 0, candelaData.Length);
            cs.FlushFinalBlock();
            return ms.ToArray();
     }

I want to convert the following algo in java, I have searched for the libraries and couldn't get anything. Help Please. ?

Darab Javaid
  • 145
  • 2
  • 13

1 Answers1

0

Darab , your best bet in Java has to be Bouncy Castle. You have API's for crypt in salting as well as the AES Rijndael as i read from the code.

For the Rejndael part you can refer : http://www.itcsolutions.eu/2011/08/24/how-to-encrypt-decrypt-files-in-java-with-aes-in-cbc-mode-using-bouncy-castle-api-and-netbeans-or-eclipse/. This gives you a fair idea of the AES part of the code and this question here Rfc2898DeriveBytes in java gives you a great idea of salting and Rfc2898 as well.

Ramachandran.A.G
  • 4,788
  • 1
  • 12
  • 24