我正在使用 code.google.com/p/go.crypto/twofish 并且我想解密从数据库中获取的密码。密码由 PHP 加密,并由 base64 编码。在 Go 中,我通过 base64 解码,转换为 []byte 并尝试解密它,但事情进展顺利。我的回报是空的。这是我的代码:
func TwofishDecrypt(key, text []byte) ([]byte, error) {
block, err := twofish.NewCipher(key)
if err != nil {
return nil, err
}
if len(text) < twofish.BlockSize {
return nil, errors.New("ciphertext too short")
}
iv := text[:twofish.BlockSize]
text = text[twofish.BlockSize:]
cfb := cipher.NewCFBDecrypter(block, iv)
cfb.XORKeyStream(text, text)
data, err := base64.StdEncoding.DecodeString(string(text))
if err != nil {
return nil, err
}
return data, nil
}