DES encryption ---- notes

enc = Cipher.getInstance("DES/CBC/PKCS5Padding"); keySpec = new SecretKeySpec(key, "DES");//key ivSpec = new IvParameterSpec(iv);//iv enc.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec); enc.doFinal(indata);//encrypt

DES can have these types of models: Electronic Codebook (ECB), Cipher Block Chaining (CBC), Cipher Feedback (CFB), Output Feedback (OFB) is the most basic ECB mode, CBC and other models are improved. Disadvantage ECB mode is identical to the same plaintext encrypted ciphertext, the plaintext to the ciphertext law. \\ Since DES is a block cipher, a block to 8 bytes, so that things to be encrypted is divided into an integer multiple of 8 bytes, it is insufficient to fill. PKCS5Padding this filling, the total number of bytes of the byte represents filled filled: for example, three bytes, then the difference is @@@@@ fill 333 bytes to fill differential is no difference to fill @ 7777777 88888888 read so long as the last byte of content to know which bytes are filled. There are other ways to fill: ISO10126-2Padding ISO7816-4Padding X9.23Padding TBCPadding ZeroBytePadding

http://www.iteye.com/topic/152405

http://www.cnblogs.com/janken/archive/2012/04/05/2432930.html  

   DES Several works

The first embodiment of the present electron dense (ECB) 64 plain text into n-bit packets, if the plaintext bit length is not a multiple of 64, the appropriate number of filling a predetermined symbol at the end of the plaintext. Encrypts plaintext groups respectively given key, the row ciphertext C = (C0, C1, ......, Cn-1) where Ci = DES (K, xi), i = 0,1, ... .., n-1. The second ciphertext chaining mode (CBC) in the CBC mode, each plaintext xi group with a group of first ciphertext bitwise die after two and before encrypted, then sent to the DES encryption, the CBC mode overcomes the ECB system messages set of heavy disadvantages, but since the front with a set of plaintexts encrypted ciphertext, and therefore the former group ciphertext error propagated to the next group. The third cipher feedback mode (CFB), the sequence may be used for clear text password X = (x0, x1, ......, xn-1), wherein the fourth xi 0 feedback manner from the output of t bits (OFB), available CFB password in sequence only difference is taken directly OFB t DES output bits, rather than taking t ciphertext bits, the rest are the same as the CFB. But it takes the output of the DES, it overcomes the disadvantages of several ways to fill the CFB DES ciphertext error propagation DES encryption algorithm is 64 bits of data, such as data bits less than a multiple of 64 bits need to be filled, It added to a multiple of 64 bits.

   NoPadding API or algorithm itself does not process the data, the encrypted data encryption agreed upon by both parties to fill algorithm. For example if the encryption and decryption of string data that can complement \ 0 or space, and then trim

   PKCS5Padding before encryption: data length of 8 bytes modulo a remainder of m, if m> 0, the byte complement 8-m, 8-byte value of m, i.e. the difference between a few bytes to make up the words section, byte value is the number of bytes added, if 0 is added 8 bytes 8

 

Reproduced in: https: //www.cnblogs.com/hubcarl/articles/3109538.html

Guess you like

Origin blog.csdn.net/weixin_34067980/article/details/93817340