Go - Decoding the password encoded by twofish

620 views Asked by At

I'm using code.google.com/p/go.crypto/twofish and I want to decrypt password, which I get from database. The password was encrypt by PHP and it's encoded by base64. In Go, I decode by base64, convert to []byte and I tried decrypt it, but something was going right. My return is empty. It's my code:

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
}
0

There are 0 answers