How to encrypt data using AES in Java

2020-06-16 03:36发布

问题:

I wish to encrypt a piece of data using AES (cbc) in java , I Want to use my own IV, which I have held in a byte array and my own key held in a byte array.

How would I go about doing this?

I'm searching for it to find tutorials on this topic.

回答1:

This is probably the best guide that I've found on the subject. It explains the basics, one concept at a time, in simple terms.



回答2:

Formally it encrypts the string into unreadable format. Use same code to decrypt.

ENCRYPT:

    String s1="arshad";

    char[] s2=s1.toCharArray();
    int s3= s2.length;
    System.out.println(s3);
   int i=0;
   // for(int j=0;j<s3;j++)
          //  System.out.println(s2[j]);

       for(i=0;i<((s3)/2);i++)
        {
            char z,f=10;
            z=(char) (s2[i] * f);
            s2[i]=s2[(s3-1)-i];
            s2[(s3-1)-i]=z;
            String b=new String(s2);
            print(b);
        }