I have two programs on C++ and Go for encrypt data using AES, but they returns different results. Could you explain me the difference? How I can write similar code to get the same result using Go?
C++
g++ aes.cpp -o aes -O3 -lcrypto -std=c++11 && ./aes
#include <iostream>
#include <openssl/aes.h>
using std::cout;
int main(int argc, char const *argv[]) {
uint8_t result[16] = {0};
uint8_t key[32] = {
52, 51, 51, 100, 52, 53, 98, 57, 51, 98, 98, 98, 102, 102, 56, 100,
54, 53, 53, 49, 55, 56, 54, 51, 50, 102, 49, 56, 101, 97, 101, 97,
};
uint8_t data[16] = {
89, 0, 192, 238, 251, 3, 19, 11, 0, 0, 0, 0, 0, 15, 0, 236,
};
AES_KEY ctx;
AES_set_encrypt_key(&key[0], 128, &ctx);
AES_encrypt(data, result, &ctx);
std::cout << "Result: ";
for (auto const& value: result) {
std::cout << unsigned(value) << ",";
}
std::cout << '
';
return 0;
}
Result: 65,68,199,89,141,129,6,202,211,198,47,54,212,0,243,130
Go
package main
import (
"crypto/aes"
"log"
)
func main() {
result := make([]byte, 16)
key := []byte{
52, 51, 51, 100, 52, 53, 98, 57, 51, 98, 98, 98, 102, 102, 56, 100,
54, 53, 53, 49, 55, 56, 54, 51, 50, 102, 49, 56, 101, 97, 101, 97,
}
data := []byte{89, 0, 192, 238, 251, 3, 19, 11, 0, 0, 0, 0, 0, 15, 0, 236}
cipher, err := aes.NewCipher(key)
if err != nil {
log.Fatal(err)
}
cipher.Encrypt(result, data)
log.Println(result)
}
Result: 18 144 147 200 175 53 202 191 80 17 142 126 228 220 57 180