2020-11-01 | Csharp | UNLOCK

Java Shiro AESEncrypt (Csharp ClassDemo)

(Class)Aesencrypt.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;

class demo{
public static void Main(string[] args){
byte[] str = {100};
byte[] key = {144,241,254,108,140,100,228,61,157,121,152,136,197,198,154,104};
byte[] IV = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
String crypt = AesEncrypt(str,key,IV) ;
}
private static string AesEncrypt(byte[] str, byte[] key, byte[] IVString)
{
Encoding encoder = Encoding.UTF8;
byte[] toEncryptArray = str;
RijndaelManaged rm = new RijndaelManaged
{
Key = key,
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7,
IV = IVString,
};
ICryptoTransform cTransform = rm.CreateEncryptor();
List<byte> temp = new List<byte>();
byte[] hexstart = IVString;
byte[] hexend = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
temp.AddRange(hexstart);
temp.AddRange(hexend);
var inject_payload = new byte[temp.Count];
temp.CopyTo(inject_payload);
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
return Convert.ToBase64String(inject_payload);
}
}

评论加载中