入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

加密中的填充(padding)技术

创建时间:2013-09-05 投稿人: 浏览次数:5114

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

 

 

声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。