我正在使用code.google.com/p/go.crypto/twofish,我想解密密码,我从数据库中获取密码。密码由PHP加密,由base64编码。在Go中,我通过base64解码,转换为[]字节,我尝试解密它,但有些事情是正确的。我的回归是空的。这是我的代码:
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
}