背景
需要一种可以编码和解码[6]字节的密码。
std 函数 aes.NewCipher 不允许这样做,因为它的块大小定义是 16 字节。
不能简单地将 6 个字节填充到 16 个字节。我需要打印 [6]byte 作为条形码并使用条形码进行远程和远程解码。
代码
这可以在去操场上运行
// You can edit this code!
// Click here and start typing.
package main
import (
"bytes"
"crypto/aes"
"fmt"
)
func main() {
plain := []byte("4512wqdeqwbuobouihodqwbuo")[:6]
encrypt := make([]byte, 6)
plain2 := make([]byte, 6)
cipher, err := aes.NewCipher([]byte("4512wqdeqwbuobouihodqwbuo")[:16])
if err != nil {
fmt.Println(err)
return
}
cipher.Encrypt(encrypt, plain)
cipher.Decrypt(plain2, encrypt)
if bytes.Compare(plain, plain2) != 0 {
fmt.Println("can't be", plain, plain2, encrypt)
}
}
错误:加密/aes:输入未满块
问题
是否有第三方功能可以满足我的要求?
或者 std 函数可以以某种方式实现这一点?
通过位移和异或来实现这个指定的功能很幼稚,还有更多吗?
对于新的,我已经用位移实现了这个功能。
POPMUISE
相关分类