About the desede/cbc/pkcs5padding in DES encryption

Source: Internet
Author: User
Tags pkcs7

Today see a 3DES encryption algorithm code, with the parameters is desede/cbc/pkcs5padding, feel more unfamiliar, so learned a bit.

The Java code encountered is as follows:

Cipher cipher=cipher.getinstance ("desede/cbc/pkcs5padding");

Previously written code, given the parameters are des or desede. In fact, Desede is shorthand, and it is equivalent to desede/ecb/pkcs5padding. This parameter is divided into three segments.

-The first paragraph is the name of the cryptographic algorithm, such as Desede is actually 3-des. This section can also put other symmetric encryption algorithms, such as Blowfish.

-The second paragraph is the block encryption mode, in addition to CBC and ECB, it can be none/cfb/qfb and so on. The most common is CBC and ECB. Des uses packet encryption to encrypt plaintext in 8-byte (64-bit) groupings. If each group is handled independently, it is the ECB. The CBC processing method is to first use the initial Vector IV for the first set of encryption, and then use the first set of ciphertext as the key to the second group of encryption, and then complete the entire encryption operation. If the contents of two groupings in clear text are the same, the ECB will get exactly the same ciphertext, but CBC will not.

-the third paragraph refers to the Fill method of the last grouping. In most cases, clear text is not just a multiple of 64 bits. For the last group, if the length is less than 64 bits, the data needs to be populated to 64 bits. Pkcs5padding is a common method of filling, and if not specified, the default is it.

To add, although the valid key length of DES is 56 bits, the required key length is 64 bits (8 bytes). 3DES requires 24 bytes.

C#

Sometimes the contents of Java encryption in C # can not be decrypted, the general reason is that the parameters are set incorrectly. The TripleDES object acquired by C # must have the mode and padding two properties set. mode and padding are enumerated types. Mode has corresponding enumeration values for the ECB and CBC, but the padding pkcs5padding need to correspond to PKCS7.

Sample code

TripleDES d = tripledes.create ();

D.mode = CIPHERMODE.CBC;

d.padding = PADDINGMODE.PKCS7;

About the desede/cbc/pkcs5padding in DES encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.