我不明白如何在 DES 中使用初始向量。我已经阅读了初始向量的公式是如何使用 CBC 模式块密码模式操作的。如何将我的明文实现到公式中。我可以举例说明吗
明文 = 计算机,二进制 = 01000011 01001111 01001101 01010000 01010101 01010100 01000101 01010010,十六进制 = 43 4F 4D 50 55 54 45 52| 密钥 = ENCRYPTT,二进制 = 01000101 01001110 01000011 01010010 01011001 01010000 01010100 01010100,十六进制 = 45 4E 43 52 59 50 54 54
谢谢
更新 :
我有两个 DES 加密项目。第一个项目使用库,第二个项目没有库。第一个项目使用库,使用CBC加密模式,第二个项目没有库,不加密模式。加密的密文导致第一个和第二个不同的程序。问题是我应该在密文相同结果的第二个程序中添加什么。如何在没有库的情况下在我的第二个程序中添加 CBC 模式。
第一个带有库的项目代码:
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.Mode = CipherMode.CBC;
没有库的第二个项目代码:
public void getAll_RL()
{
string proses = "";
List<string> R = new List<string>();
List<string> L = new List<string>();
R.Add(txtR0.Text);
R.Add(txtR1.Text);
L.Add(txtL0.Text);
L.Add(txtL1.Text);
L.Add(txtR1.Text);
for (int x = 2; x <= 16; x++)
{
txtProses.Text = string.Empty;
string resultEks = string.Empty;
cp.Table(R[x - 1], "E", ref resultEks); //Tabel Ekspansi
string resultXOR = string.Empty;
string subKey = (string)DGVSubKey.Rows[x - 1].Cells[1].Value;
cp.XOR(resultEks, subKey, ref resultXOR);
string resultSBOX = string.Empty;
cp.SBOX(resultXOR, ref resultSBOX);
string resultPBOX = string.Empty;
cp.Table(resultSBOX, "PBOX", ref resultPBOX);
string resultXOR2 = string.Empty;
cp.XOR(resultPBOX, L[x - 1], ref resultXOR2);
R.Add(resultXOR2);
L.Add(resultXOR2);
}
txtL16.Text = L[16];
txtR16.Text = R[16];
txtRL16.Text = R[16] + L[16] ;
}
public void getIP1()
{
string RL16 = txtRL16.Text;
if (RL16.Length == 64)
{
string result = string.Empty;
cp.Table(RL16, "IP1", ref result);
txtIP1.Text = result;
}
}
public void getHexResult()
{
string IP1 = txtIP1.Text;
if (IP1.Length == 64)
{
List<string> AllBinary = new List<string>();
string Hex = string.Empty;
string ResultHex = string.Empty;
for (int x = 0; x < 8; x++)
{
string string8 = IP1.Substring(8 * x, 8);
AllBinary.Add(string8);
string hex = Convert.ToInt64(AllBinary[x], 2).ToString("X");
Hex += hex + " ";
}
string[] hexSplit = Hex.TrimEnd().Split(' ');
for (int x = 0; x < 8; x++)
{
if (hexSplit[x].Length == 1)
{
ResultHex += "0" + hexSplit[x] +" ";
}
else
{
ResultHex += hexSplit[x] + " ";
}
}
txtHexResult.Text = ResultHex.TrimEnd();
}
}
结果 Cipertext(十六进制):
第一个项目:2B B7 4F 52 A8 0E 9F 0F,第二个项目:A6 53 62 DD FD 25 A0 C5