qcode
  • 创作工场专业版,一问多答!更智能、更完整、更原创
  • 这是一个超强内容创作平台,它会写文章、做设计、绘图、敲代码,有问必答!
🔥点击使用-免登录深度版🔥

用go实现cfb1模式

时间2023-04-18 11:40:43 提问来自 四川省阿坝州 的网友 分类创作 浏览383
```go package cfb1 import ( "crypto/cipher" "errors" ) // NewCFB1 returns a stream cipher that implements CFB-1 mode. The key argument should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256. func NewCFB1(key []byte) (cipher.Stream, error) { // check key length is valid for AES encryption algorithm if len(key) != 16 && len(key) != 24 && len(key) != 32 { // not valid key length for AES encryption algorithm return nil, errors.New("invalid key size") // return an error if invalid key length is provided } else { // valid key length for AES encryption algorithm // create a new instance of cfb1 struct and return it as type of cipher.Stream interface return &cfb1{aesCipher: newAESCipher(key), blockSize: aesBlockSize}, nil // return new instance of cfb1 struct as type of cipher.Stream interface if valid key length is provided } } // cfb1 struct implements the cipher.Stream interface type cfb1 struct { aesCipher *aesCipher blockSize int } func (c *cfb1) XORKeyStream(dst, src []byte) { for i := 0; i < len(src); i += c.blockSize { var block [16]byte copy(block[:], src[i:i+c.blockSize]) c.aesCipher.Encrypt(&block) xorBytes(&dst[i], &src[i], &block[0], c.blockSize) } }

不满意?免费深度重写!

免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。

上一篇 加盟自助棋牌室的五大原因 下一篇 消防员关于深入贯彻中央八项规定精神学习的心得体会