Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
C#Diff
建立於
2 年前
差異永不過期
清除
匯出
分享
解釋
2 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
64 行
全部複製
5 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
63 行
全部複製
using System;
using System;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text;
using System.Text;
class SSN
class SSN
{
{
public string EncryptString(string plainString, string keyString, string encryptionIV)
public string EncryptString(string plainString, string keyString, string encryptionIV)
{
{
複製
已複製
複製
已複製
byte[] key = Encoding.UTF8.GetBytes(keyString
);
byte[] key = Encoding.UTF8.GetBytes(keyString
.Substring(0, 16)
);
byte[] iv = Encoding.UTF8.GetBytes(encryptionIV
);
byte[] iv = Encoding.UTF8.GetBytes(encryptionIV
.Substring(0, 16)
);
using (Aes aesAlg = Aes.Create())
using (Aes aesAlg = Aes.Create())
{
{
複製
已複製
複製
已複製
aesAlg.KeySize = 128;
aesAlg.Key = key;
aesAlg.Key = key;
aesAlg.IV = iv;
aesAlg.IV = iv;
aesAlg.Mode = CipherMode.CBC;
aesAlg.Mode = CipherMode.CBC;
aesAlg.Padding = PaddingMode.None;
aesAlg.Padding = PaddingMode.None;
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);
byte[] plainBytes = Encoding.UTF8.GetBytes(plainString);
byte[] plainBytes = Encoding.UTF8.GetBytes(plainString);
int blockSize = 16;
int blockSize = 16;
int paddingNeeded = blockSize - (plainBytes.Length % blockSize);
int paddingNeeded = blockSize - (plainBytes.Length % blockSize);
byte[] paddedBytes = new byte[plainBytes.Length + paddingNeeded];
byte[] paddedBytes = new byte[plainBytes.Length + paddingNeeded];
Array.Copy(plainBytes, paddedBytes, plainBytes.Length);
Array.Copy(plainBytes, paddedBytes, plainBytes.Length);
for (int i = plainBytes.Length; i < paddedBytes.Length; i++)
for (int i = plainBytes.Length; i < paddedBytes.Length; i++)
{
{
paddedBytes[i] = (byte)paddingNeeded;
paddedBytes[i] = (byte)paddingNeeded;
}
}
byte[] encryptedBytes = encryptor.TransformFinalBlock(paddedBytes, 0, paddedBytes.Length);
byte[] encryptedBytes = encryptor.TransformFinalBlock(paddedBytes, 0, paddedBytes.Length);
return Convert.ToBase64String(encryptedBytes);
return Convert.ToBase64String(encryptedBytes);
}
}
}
}
public string DecryptString(string encryptedString, string keyString, string encryptionIV)
public string DecryptString(string encryptedString, string keyString, string encryptionIV)
{
{
複製
已複製
複製
已複製
byte[] key = Encoding.UTF8.GetBytes(keyString
);
byte[] key = Encoding.UTF8.GetBytes(keyString
.Substring(0, 16)
);
byte[] iv = Encoding.UTF8.GetBytes(encryptionIV
);
byte[] iv = Encoding.UTF8.GetBytes(encryptionIV
.Substring(0, 16)
);
using (Aes aesAlg = Aes.Create())
using (Aes aesAlg = Aes.Create())
{
{
複製
已複製
複製
已複製
aesAlg.KeySize = 128;
aesAlg.Key = key;
aesAlg.Key = key;
aesAlg.IV = iv;
aesAlg.IV = iv;
aesAlg.Mode = CipherMode.CBC;
aesAlg.Mode = CipherMode.CBC;
aesAlg.Padding = PaddingMode.None;
aesAlg.Padding = PaddingMode.None;
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);
byte[] encryptedBytes = Convert.FromBase64String(encryptedString);
byte[] encryptedBytes = Convert.FromBase64String(encryptedString);
byte[] decryptedBytes = decryptor.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length);
byte[] decryptedBytes = decryptor.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length);
int paddingByte = decryptedBytes[decryptedBytes.Length - 1];
int paddingByte = decryptedBytes[decryptedBytes.Length - 1];
int unpaddedLength = decryptedBytes.Length - paddingByte;
int unpaddedLength = decryptedBytes.Length - paddingByte;
return Encoding.UTF8.GetString(decryptedBytes, 0, unpaddedLength);
return Encoding.UTF8.GetString(decryptedBytes, 0, unpaddedLength);
}
}
}
}
}
}
複製
已複製
複製
已複製
已保存差異
原始文本
開啟檔案
using System; using System.Security.Cryptography; using System.Text; class SSN { public string EncryptString(string plainString, string keyString, string encryptionIV) { byte[] key = Encoding.UTF8.GetBytes(keyString); byte[] iv = Encoding.UTF8.GetBytes(encryptionIV); using (Aes aesAlg = Aes.Create()) { aesAlg.KeySize = 128; aesAlg.Key = key; aesAlg.IV = iv; aesAlg.Mode = CipherMode.CBC; aesAlg.Padding = PaddingMode.None; ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); byte[] plainBytes = Encoding.UTF8.GetBytes(plainString); int blockSize = 16; int paddingNeeded = blockSize - (plainBytes.Length % blockSize); byte[] paddedBytes = new byte[plainBytes.Length + paddingNeeded]; Array.Copy(plainBytes, paddedBytes, plainBytes.Length); for (int i = plainBytes.Length; i < paddedBytes.Length; i++) { paddedBytes[i] = (byte)paddingNeeded; } byte[] encryptedBytes = encryptor.TransformFinalBlock(paddedBytes, 0, paddedBytes.Length); return Convert.ToBase64String(encryptedBytes); } } public string DecryptString(string encryptedString, string keyString, string encryptionIV) { byte[] key = Encoding.UTF8.GetBytes(keyString); byte[] iv = Encoding.UTF8.GetBytes(encryptionIV); using (Aes aesAlg = Aes.Create()) { aesAlg.KeySize = 128; aesAlg.Key = key; aesAlg.IV = iv; aesAlg.Mode = CipherMode.CBC; aesAlg.Padding = PaddingMode.None; ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); byte[] encryptedBytes = Convert.FromBase64String(encryptedString); byte[] decryptedBytes = decryptor.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length); int paddingByte = decryptedBytes[decryptedBytes.Length - 1]; int unpaddedLength = decryptedBytes.Length - paddingByte; return Encoding.UTF8.GetString(decryptedBytes, 0, unpaddedLength); } } }
更改後文本
開啟檔案
using System; using System.Security.Cryptography; using System.Text; class SSN { public string EncryptString(string plainString, string keyString, string encryptionIV) { byte[] key = Encoding.UTF8.GetBytes(keyString.Substring(0, 16)); byte[] iv = Encoding.UTF8.GetBytes(encryptionIV.Substring(0, 16)); using (Aes aesAlg = Aes.Create()) { aesAlg.Key = key; aesAlg.IV = iv; aesAlg.Mode = CipherMode.CBC; aesAlg.Padding = PaddingMode.None; ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); byte[] plainBytes = Encoding.UTF8.GetBytes(plainString); int blockSize = 16; int paddingNeeded = blockSize - (plainBytes.Length % blockSize); byte[] paddedBytes = new byte[plainBytes.Length + paddingNeeded]; Array.Copy(plainBytes, paddedBytes, plainBytes.Length); for (int i = plainBytes.Length; i < paddedBytes.Length; i++) { paddedBytes[i] = (byte)paddingNeeded; } byte[] encryptedBytes = encryptor.TransformFinalBlock(paddedBytes, 0, paddedBytes.Length); return Convert.ToBase64String(encryptedBytes); } } public string DecryptString(string encryptedString, string keyString, string encryptionIV) { byte[] key = Encoding.UTF8.GetBytes(keyString.Substring(0, 16)); byte[] iv = Encoding.UTF8.GetBytes(encryptionIV.Substring(0, 16)); using (Aes aesAlg = Aes.Create()) { aesAlg.Key = key; aesAlg.IV = iv; aesAlg.Mode = CipherMode.CBC; aesAlg.Padding = PaddingMode.None; ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); byte[] encryptedBytes = Convert.FromBase64String(encryptedString); byte[] decryptedBytes = decryptor.TransformFinalBlock(encryptedBytes, 0, encryptedBytes.Length); int paddingByte = decryptedBytes[decryptedBytes.Length - 1]; int unpaddedLength = decryptedBytes.Length - paddingByte; return Encoding.UTF8.GetString(decryptedBytes, 0, unpaddedLength); } } }
尋找差異