Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert code to java

2946523May 8 2015 — edited May 8 2015

I have some c# code. I tried to convert this into java.
I didn't get success in it.

public static string Encrypt(string input, string pass)

    {

        System.Security.Cryptography.RijndaelManaged AES = new System.Security.Cryptography.RijndaelManaged();

        System.Security.Cryptography.MD5CryptoServiceProvider Hash_AES = new System.Security.Cryptography.MD5CryptoServiceProvider();

        string encrypted = "";

       try

        {

            byte[] hash = new byte[32];

            byte[] temp = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass));

            Array.Copy(temp, 0, hash, 0, 16);

            Array.Copy(temp, 0, hash, 15, 16);

           AES.Key = hash;

            AES.Mode = System.Security.Cryptography.CipherMode.ECB;

            System.Security.Cryptography.ICryptoTransform DESEncrypter = AES.CreateEncryptor();

            byte[] Buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(input);

            encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length));

        }

       catch

        return encrypted;

    }

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2015
Added on May 8 2015
0 comments
537 views