日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# aes解密 java,C#实现的AES加密解密完整实例

發(fā)布時間:2023/12/18 C# 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# aes解密 java,C#实现的AES加密解密完整实例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文實例講述了C#實現(xiàn)的AES加密解密。分享給大家供大家參考,具體如下:

/******************************************************************

* 創(chuàng)建人:HTL

* 說明:C# AES加密解密

*******************************************************************/

using System;

using System.Security.Cryptography;

using System.Text;

using System.IO;

public class Test

{

public static void Main()

{

//密碼

string password="1234567890123456";

//加密初始化向量

string iv=" ";

string message=AESEncrypt("abcdefghigklmnopqrstuvwxyz0123456789",password,iv);

Console.WriteLine(message);

message=AESDecrypt("8Z3dZzqn05FmiuBLowExK0CAbs4TY2GorC2dDPVlsn/tP+VuJGePqIMv1uSaVErr",password,iv);

Console.WriteLine(message);

}

///

/// AES加密

///

/// 加密字符

/// 加密的密碼

/// 密鑰

///

public static string AESEncrypt(string text, string password, string iv)

{

RijndaelManaged rijndaelCipher = new RijndaelManaged();

rijndaelCipher.Mode = CipherMode.CBC;

rijndaelCipher.Padding = PaddingMode.PKCS7;

rijndaelCipher.KeySize = 128;

rijndaelCipher.BlockSize = 128;

byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(password);

byte[] keyBytes = new byte[16];

int len = pwdBytes.Length;

if (len > keyBytes.Length) len = keyBytes.Length;

System.Array.Copy(pwdBytes, keyBytes, len);

rijndaelCipher.Key = keyBytes;

byte[] ivBytes = System.Text.Encoding.UTF8.GetBytes(iv);

rijndaelCipher.IV = new byte[16];

ICryptoTransform transform = rijndaelCipher.CreateEncryptor();

byte[] plainText = Encoding.UTF8.GetBytes(text);

byte[] cipherBytes = transform.TransformFinalBlock(plainText, 0, plainText.Length);

return Convert.ToBase64String(cipherBytes);

}

///

/// AES解密

///

///

///

///

///

public static string AESDecrypt(string text, string password, string iv)

{

RijndaelManaged rijndaelCipher = new RijndaelManaged();

rijndaelCipher.Mode = CipherMode.CBC;

rijndaelCipher.Padding = PaddingMode.PKCS7;

rijndaelCipher.KeySize = 128;

rijndaelCipher.BlockSize = 128;

byte[] encryptedData = Convert.FromBase64String(text);

byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(password);

byte[] keyBytes = new byte[16];

int len = pwdBytes.Length;

if (len > keyBytes.Length) len = keyBytes.Length;

System.Array.Copy(pwdBytes, keyBytes, len);

rijndaelCipher.Key = keyBytes;

byte[] ivBytes = System.Text.Encoding.UTF8.GetBytes(iv);

rijndaelCipher.IV = ivBytes;

ICryptoTransform transform = rijndaelCipher.CreateDecryptor();

byte[] plainText = transform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);

return Encoding.UTF8.GetString(plainText);

}

}

PS:關(guān)于加密解密感興趣的朋友還可以參考本站在線工具:

密碼安全性在線檢測:

高強度密碼生成器:

MD5在線加密工具:

迅雷、快車、旋風(fēng)URL加密/解密工具:

在線散列/哈希算法加密工具:

希望本文所述對大家C#程序設(shè)計有所幫助。

總結(jié)

以上是生活随笔為你收集整理的c# aes解密 java,C#实现的AES加密解密完整实例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。