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); } } }
查找差异