Openssl_encrypt an decrypt in GO?

Hi everyone,

i’m new on the forum, it’s my first topic :slight_smile:

I’m sorry for a translation.

I need to encrypt with the same method to openssl_encrypt (PHP), i don’t find a solution. I have tried to decrypt an encrypted data, encrypted with openssl_decrypt in order to do it the other way around afterwards, but this doesn’t work.

i need to reproduce this in go:

$crypted = openssl_encrypt(
serialize($unencrypted_data),
‘AES-256-CTR’,
$key,
0,
$iv
);

i tried the opposit (decrypt an encrypted data with openssl_encrypt):

package main

import (
“crypto/aes”
“crypto/cipher”
“encoding/base64”
“fmt”
)

func main() {
iv, _ := base64.StdEncoding.DecodeString(“NjIxNDM4MTFjODFhODRkYw==”)
fmt.Println(string(iv))

key := []byte("key")
fmt.Println(string(key))

text, _ := base64.StdEncoding.DecodeString("TktXS3hKWnFZY3YwTXVpR0JKR0pYMkU4SlJ5aWFSZC9DZDJFaW1xdHNxVmZMT2JGUFI0YnRzakxMVkJsS1YyWEpYUEo0R2k4UDhGSERkQkRRTWtxUWcrbnhkU2NtTXlBTHJaM2M4cSs=")
fmt.Println(text)

cipherBlock, _ := aes.NewCipher(key)
fmt.Println(cipherBlock)

mode := cipher.NewCBCDecrypter(cipherBlock, iv)	
mode.CryptBlocks(text[0:64], text[0:64])
fmt.Println(string(text))

}

the result (not correct): �Zf�^��7jZ��X}lM�ܿ/�:��w�kt5�����Z��|�pM�+/�?J��ʍ�_e��JXPJ4Gi8P8FHDdBDQMkqQg+nxdScmMyALrZ3c8q+

thank you

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.