support for AES in JCE, supported modes and fill modesAES in JCE supports v mode: CBC,CFB,ECB,OFB,PCBC; supports three kinds of padding: nopadding,pkcs5padding,iso10126padding. Ssl3padding is not supported. The "NONE" mode is not supported. where aes/ecb/nopadding and I now use the same results as the aesutil (in the case of an integer multiple of 16). When the AES algorithm is obtained without a pattern and padding, it uses ecb/pkcs5padding by default. Algorithm/mode/padding 16 bytes After encrypted data length less than 16 bytes after encryption length aes/cbc/nopadding 16 not supported
Aes/cbc/pkcs5padding 32 16
Aes/cbc/iso10126padding 32 16
Aes/cfb/nopadding 16 Raw data length
Aes/cfb/pkcs5padding 32 16
Aes/cfb/iso10126padding 32 16
Aes/ecb/nopadding 16 Not supported
Aes/ecb/pkcs5padding 32 16
Aes/ecb/iso10126padding 32 16
Aes/ofb/nopadding 16 Raw data length
Aes/ofb/pkcs5padding 32 16
Aes/ofb/iso10126padding 32 16
Aes/pcbc/nopadding 16 Not supported
Aes/pcbc/pkcs5padding 32 16
Aes/pcbc/iso10126padding 32 16 You can see that when the original data length is an integer multiple of 16, if the original data length equals 16*n, the data length is equal to 16*n when the nopadding is used. , the length of the encrypted data is equal to 16* (n+1) in other cases. In the case of an integral multiple of less than 16, if the original data length equals 16*n+m[where M is less than 16], the length of the encrypted data is equal to 16* (n+1) in any way other than the nopadding fill; The ECB and PCBC three modes are not supported, and in CFB, ofb two modes the length of the encrypted data is equal to the original data length.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------
the following turn from http://my.oschina.net/Jacker/blog/86383
AES encryption CBC mode compatible with four different programming language platforms "PHP, Javascript, Java, C #" 7 people collection This article, I want to bookmark posted 11 months ago (2012-10-31 22:19), there are 3549 Reads, a total of reviews
Because of my side dishes, began to AES encryption does not understand, on the network spent more time to review data collation;
First simple from Baidu to introduce:
1 |
The Advanced Encryption Standard in cryptography (Advanced Encryption Standard,aes), also known as the High Encryption Standard Rijndael encryption method, |
2 |
is a block encryption standard used by the United States federal government. This standard is used to replace the original DES, which has been analyzed by many parties and widely |
3 |
are used. After five years of selection process, advanced encryption standards by the National Institute of Standards and Technology (NIST) on November 26, 2001 |
4 |
Published in FIPS PUB197 and became a valid standard on May 26, 2002. 2006, advanced Encryption Standard has become symmetric key encryption |
5 |
One of the most popular algorithms. The algorithm was designed for the Belgian cryptology Joan Daemen and Vincentrijmen, combining the names of two authors |
6 |
The selection process for the Advanced Encryption Standard, named after Rijndael. (The pronunciation of Rijdael is close to "Rhinedoll". ) |
AES Encryption mode and fill method (in fact, there are several types of filling not written, the beginning of the same time around here)
01 |
Algorithm/mode/padding 16 bytes After encrypted data length less than 16 bytes after encrypted length |
02 |
Aes/cbc/nopadding 16 Not supported |
03 |
Aes/cbc/pkcs5padding 32 16 |
04 |
Aes/cbc/iso10126padding 32 16 |
05 |
Aes/cfb/nopadding 16 Raw data length |
06 |
Aes/cfb/pkcs5padding 32 16 |
07 |
Aes/cfb/iso10126padding 32 16 |
08 |
Aes/ecb/nopadding 16 Not supported |
09 |
Aes/ecb/pkcs5padding 32 16 |
10 |
Aes/ecb/iso10126padding 32 16 |
11 |
Aes/ofb/nopadding 16 Raw data length |
12 |
Aes/ofb/pkcs5padding 32 16 |
13 |
Aes/ofb/iso10126padding 32 16 |
14 |
Aes/pcbc/nopadding 16 Not supported |
15 |
Aes/pcbc/pkcs5padding 32 16 |
16 |
Aes/pcbc/iso10126padding 32 16 |
More about cryptographic mode content: http://blog.sina.com.cn/s/blog_679daa6b0100zmpp.html
See so many patterns, already a little dizzy, then my goal is to find PHP, Javascript, Java, C # AES Encryption mode of an intersection;
After a round of search, information Baidu Google these two teachers, found an article about PHP and Java AES Interoperability-compatible encryption articles, after reading
found that the original PHP AES encryption fill only zeropadding (0-because the data length is not an integer multiple of 16 to fill), and Java is not
There is this filling mode, the cup can only write one of their own, the Java fill mode with nopadding (not fill the content);
Java-side code:
02 |
* To change this template, choose Tools | Templates |
03 |
* and open the template in the editor. |
11 |
Import Javax.crypto.Cipher; |
12 |
Import Javax.crypto.spec.IvParameterSpec; |
13 |
Import Javax.crypto.spec.SecretKeySpec; |
14 |
Import Sun.misc.BASE64Decoder; |
16 |
public class encryption |
18 |
public static void Main (String args[]) throws Exception { |
19 |
System.out.println (Encrypt ()); |
20 |
System.out.println (Desencrypt ()); |
23 |
public static String Encrypt () throws Exception { |
25 |
String data = "Test String"; |
26 |
String key = "1234567812345678"; |
27 |
String IV = "1234567812345678"; |
29 |
Cipher Cipher = cipher.getinstance ("aes/cbc/nopadding"); |
30 |
int blockSize = Cipher.getblocksize (); |
32 |
byte[] databytes = Data.getbytes (); |
33 |
int plaintextlength = Databytes.length; |
34 |
if (plaintextlength% blockSize! = 0) { |
35 |
Plaintextlength = Plaintextlength + (blockSize-(plaintextlength% blockSize)); |