本文整理汇总了Golang中crypto/cipher.BlockMode.BlockSize方法的典型用法代码示例。如果您正苦于以下问题:Golang BlockMode.BlockSize方法的具体用法?Golang BlockMode.BlockSize怎么用?Golang BlockMode.BlockSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crypto/cipher.BlockMode
的用法示例。
在下文中一共展示了BlockMode.BlockSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Decrypt
func (c *DefaultCryptor) Decrypt(decryptor cipher.BlockMode, cipherText []byte) (msg []byte, err error) {
if decryptor != nil {
if len(cipherText) < decryptor.BlockSize() || len(cipherText)%decryptor.BlockSize() != 0 {
err = ErrInputTextSize
return
}
msg = cipherText
decryptor.CryptBlocks(msg, cipherText)
// let caller do pkcs7 unpadding
msg, err = padding.PKCS7.Unpadding(msg, decryptor.BlockSize())
}
return
}
示例2: Encrypt
func (c *DefaultCryptor) Encrypt(encryptor cipher.BlockMode, msg []byte) (cipherText []byte, err error) {
if msg != nil {
// let caller do pkcs7 padding
msg = padding.PKCS7.Padding(msg, encryptor.BlockSize())
if len(msg) < encryptor.BlockSize() || len(msg)%encryptor.BlockSize() != 0 {
err = ErrInputTextSize
return
}
cipherText = msg
encryptor.CryptBlocks(cipherText, msg)
}
return
}
示例3: newCipherBlockReader
// newCipherBlockReader returns an io.Reader that decrypts the given io.Reader using
// the provided block mode cipher.
func newCipherBlockReader(r io.Reader, mode cipher.BlockMode) io.Reader {
cr := &cipherBlockReader{r: r, mode: mode}
cr.outbuf = make([]byte, 0, mode.BlockSize())
cr.inbuf = make([]byte, 0, mode.BlockSize())
return cr
}