如题:
function E_DES_Str(Str, Key: string): string;
var
StrByte, OutByte, KeyByte: array[0..7] of Byte;
I, j: Integer;
begin
if (Length(Str) > 0) and (Ord(Str[Length(Str)]) = 0) then
raise Exception.Create('Error: the last char is NULL char.');//这里为什么要进行验证??
if Length(Key) < 8 then
while Length(Key) < 8 do
Key := Key + Chr(0);
while Length(Str) mod 8 <> 0 do
Str := Str + Chr(0); for j := 0 to 7 do
KeyByte[j] := Ord(Key[j + 1]);
makeKey(KeyByte, subKey); Result := ''; for I := 0 to Length(Str) div 8 - 1 do
begin
for j := 0 to 7 do
StrByte[j] := Ord(Str[I * 8 + j + 1]);
desData(dmEncry, StrByte, OutByte);
for j := 0 to 7 do
Result := Result + Chr(OutByte[j]);
end;
end;
这是最常见的网上的Delphi对DES加密方法中的一个加密函数,该函数第一条语句就是验证串的结尾是不是一个空字符,为什么要这样验证呢?如果是空字符的话,对加密有什么影响吗?求解!!!
function E_DES_Str(Str, Key: string): string;
var
StrByte, OutByte, KeyByte: array[0..7] of Byte;
I, j: Integer;
begin
if (Length(Str) > 0) and (Ord(Str[Length(Str)]) = 0) then
raise Exception.Create('Error: the last char is NULL char.');//这里为什么要进行验证??
if Length(Key) < 8 then
while Length(Key) < 8 do
Key := Key + Chr(0);
while Length(Str) mod 8 <> 0 do
Str := Str + Chr(0); for j := 0 to 7 do
KeyByte[j] := Ord(Key[j + 1]);
makeKey(KeyByte, subKey); Result := ''; for I := 0 to Length(Str) div 8 - 1 do
begin
for j := 0 to 7 do
StrByte[j] := Ord(Str[I * 8 + j + 1]);
desData(dmEncry, StrByte, OutByte);
for j := 0 to 7 do
Result := Result + Chr(OutByte[j]);
end;
end;
这是最常见的网上的Delphi对DES加密方法中的一个加密函数,该函数第一条语句就是验证串的结尾是不是一个空字符,为什么要这样验证呢?如果是空字符的话,对加密有什么影响吗?求解!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货