///////////////////////////////////////////////////////////function EncryStr_3DES(Str, Key: String): String;begin if Length(Key) < 16 then while Length(Key) < 16 do Key := Key + Chr(0)
Result := EncryStr(Str, Copy(Key, 1, 8))
Result := DecryStr(Result, Copy(Key, 9, 8))
Result := EncryStr(Result, Copy(Key, 1, 8));end;function DecryStr_3DES(Str, Key: String): String;begin if Length(Key) < 16 then while Length(Key) < 16 do Key := Key + Chr(0)
Result := DecryStr(Str, Copy(Key, 1, 8))
Result := EncryStr(Result, Copy(Key, 9, 8))
Result := DecryStr(Result, Copy(Key, 1, 8));end;///////////////////////////////////////////////////////////function TDESEncryStrHex(Str, Key: String): String;var I: Integer
Src, S: string
EncStr, StrResult: String;begin EncStr := ''
Src := Trim(Str)
while Length(Src) > 8 do begin S := Copy(Src, 1, 8)
EncStr := EncStr + EncryStr_3DES(S, Key)
Delete(Src, 1, 8)
end
if Length(Src) > 0 then EncStr := EncStr + EncryStr_3DES(Src, Key)
StrResult := ''
for I := 0 to Length(EncStr) - 1 do begin S := Format('%x', [Ord(EncStr[I + 1])])
if Length(S) = 1 then S := '0' + S
StrResult := StrResult + S
end
Result := StrResult;end;///////////////////////////////////////////////////////////function TDESDecryStrHex(StrHex, Key: String): String
function HexToInt(Hex: String): Integer
var I, Res: Integer
ch: Char
begin Res := 0
for I := 0 to Length(Hex) - 1 do begin ch := Hex[I + 1]
if (ch >= '0') and (ch <= '9') then Res := Res * 16 + Ord(ch) - Ord('0') else if (ch >= 'A') and (ch <= 'F') then Res := Res * 16 + Ord(ch) - Ord('A') + 10 else if (ch >= 'a') and (ch <= 'f') then Res := Res * 16 + Ord(ch) - Ord('a') + 10 else raise Exception.Create('Error: not a Hex String')
end
Result := Res
end;var I: Integer
Src, S: string
DecStr, Str: String;begin Str := ''
Src := Trim(StrHex)
for I := 0 to Length(Src) div 2 - 1 do begin S := Copy(Src, I * 2 + 1, 2)
Str := Str + Chr(HexToInt(S))
end
Src := Str
DecStr := ''
while Length(Src) > 8 do begin S := Copy(Src, 1, 8)
DecStr := DecStr + DecryStr_3DES(S, Key)
Delete(Src, 1, 8)
end
if Length(Src) > 0 then DecStr := DecStr + DecryStr_3DES(S, Key)
Result := DecStr;end;-----------------------------------------------------------------------------EncryStr函数可以找到那个标准的des函数,3des就是基于des上的。