我必须将函数从 移植到 ,这是使用加密。显然,我必须得到与我得到的相同的结果C#
GO
AES
GO
C#
我准备了一个小小提琴C#
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main()
{
var query = "csharp -> golang";
var key = Encoding.UTF8.GetBytes("12345678901234567890123456789012");
var iv = Encoding.UTF8.GetBytes("1234567890123456");
using (var aes = (RijndaelManaged)RijndaelManaged.Create())
{
aes.KeySize = 256;
aes.Mode = CipherMode.CBC;
aes.Key = key;
aes.IV = iv;
using (var transform = aes.CreateEncryptor())
{
Console.WriteLine("query => " + query);
var toEncodeByte = Encoding.UTF8.GetBytes(query);
Console.WriteLine("toEncodeByte = " + ToString(toEncodeByte));
var encrypted = transform.TransformFinalBlock(toEncodeByte, 0, toEncodeByte.Length);
Console.WriteLine("encrypted = " + ToString(encrypted));
}
}
}
public static string ToString(byte[] b)
{
return "[" + String.Join(" ", b.Select(h => h.ToString())) + "]";
}
}
控制台输出
query => csharp -> golang
toEncodeByte = [99 115 104 97 114 112 32 45 62 32 103 111 108 97 110 103]
encrypted = [110 150 8 224 44 118 15 182 248 172 105 14 61 212 219 205 216 31 76 112 179 76 214 154 227 112 159 176 24 61 108 100]
忽然笑
相关分类