加密中的填充(padding)技术

From:http://hi.baidu.com/zeorliu/item/26ec5a3861f2348af4e4ad62

 

在实践中,大部分都采用pkcs7padding方式。
http://en.wikipedia.org/wiki/Padding_(cryptography) From Wikipedia, the free encyclopedia
Padding methods
位填充(Bit padding)参考:Rfc1321( 00 ... 00 00"
字节填充(Byte padding)
ANSI X.923:... | DD DD DD DD DD DD DD DD | DD DD DD DD (00 00 00 04)|【除了最后字节,其他填0】
ISO 10126:.... | DD DD DD DD DD DD DD DD | DD DD DD DD (81 A6 23 04)|【除了最后字节,其他随机】
PKCS7(Rfc3852) | DD DD DD DD DD DD DD DD | DD DD DD DD (04 04 04 04)|参考 http://tools.ietf.org/html/rfc3852#section-6.3 【都是填充相同的值,值为填充的长度(>=1)】
Zero Padding... | DD DD DD DD DD DD DD DD | DD DD DD DD (00 00 00 00)|
http://www.di-mgt.com.au/cryptopad.html Using Padding in Encryption
We need to pad the block with padding bytes to make it up to the required length. There are at least five common conventions:-
Pad with bytes all of the same value as the number of padding bytes
Pad with 0x80 followed by zero bytes
Pad with zeroes except make the last byte equal to the number of padding bytes
Pad with zero (null) characters
Pad with space characters

This article describes the mechanics of padding with examples using common block encryption algorithms like DES, Triple DES, Blowfish and AES. It considers where you should use padding and where you don't need to.

 

             Example using DES in ECB mode

             Example using Blowfish in CBC mode

  • What about ciphers like AES that use larger block sizes?
  • Example using AES
  • Cipher-Feedback (CFB) and Output-Feedback (OFB) Modes
  • When don't I need to use padding?
  • Example using Triple DES without padding
  • Using random padding
  • So when do I use padding and when don't I?
  • References
  • Other Information

 

 

你可能感兴趣的:(C++,windows)