27. Oktober 2014 13:14
28. Oktober 2014 15:49
28. Oktober 2014 21:20
sData := 'Here is some data to encrypt.';
FileName := 'c:\temp\CText.txt';
// encrypt
fMode := fMode.OpenOrCreate;
fStream := fStream.FileStream(FileName,fMode);
TripleDESEnc := TripleDESEnc.Create('TripleDES');
cEnc := TripleDESEnc.CreateEncryptor;
cMode := cMode.Write;
cStream := cStream.CryptoStream(fStream,cEnc,cMode);
sWriter := sWriter.StreamWriter(cStream);
sWriter.WriteLine(sData);
sWriter.Close;
cStream.Close;
fStream.Close;
file.OPEN(FileName);
file.READ(sData);
file.CLOSE;
MESSAGE('Encrypted: ' + sData);
// decrypt
fMode := fMode.OpenOrCreate;
fStream := fStream.FileStream(FileName, fMode);
TripleDESDec := TripleDESDec.Create;
cDec := TripleDESDec.CreateDecryptor(TripleDESEnc.Key,TripleDESEnc.IV);
cMode := cMode.Read;
cStream := cStream.CryptoStream(fStream,cDec,cMode);
sReader := sReader.StreamReader(cStream);
sData := sReader.ReadLine;
sReader.Close;
cStream.Close;
fStream.Close;
MESSAGE('Decrypted: ' + sData);
3. November 2014 13:37
3. November 2014 14:08
Wenn die aktuelle Key-Eigenschaft null ist, wird die GenerateKey-Methode aufgerufen, um einen neuen Zufallswert für Key zu erstellen. Wenn die aktuelle IV-Eigenschaft null ist, wird die GenerateIV-Methode aufgerufen, um einen neuen Zufallswert für IV zu erstellen.
3. November 2014 16:25
3. November 2014 16:33
4. November 2014 09:47
Variablen
SourceString@1119455000 : Text[1024];
TargetString@1119455001 : Text[1024];
AESEnc@1119455015 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.Aes";
cEnc@1119455016 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.ICryptoTransform";
cMode@1119455025 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.CryptoStreamMode";
cPadding@1119455008 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.PaddingMode";
cStream@1119455026 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.CryptoStream";
sWriter@1119455027 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamWriter";
dStream@1119455002 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";
dBytes@1119455003 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";
dConvert@1119455004 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert";
CharIndex@1119455018 : Integer;
KeyString@1119455019 : Text[32];
KeyCharArr@1119455020 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Array";
CipherMode@1119455021 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Security.Cryptography.CipherMode";
ArrayType@1119455022 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Type";
TmpByte@1119455023 : Byte;
Code:
SourceString := 'ABC';
KeyString := 'abcdefghijklmnoqprstuvwxyz012345';
ArrayType := ArrayType.GetType('System.Byte',FALSE);
KeyCharArr := KeyCharArr.CreateInstance(ArrayType,STRLEN(KeyString));
FOR CharIndex := 1 TO STRLEN(KeyString) DO BEGIN
TmpByte := KeyString[CharIndex];
KeyCharArr.SetValue(TmpByte,CharIndex - 1);
END;
AESEnc := AESEnc.Create('AesManaged');
AESEnc.KeySize(256);
AESEnc.Mode(CipherMode.ECB);
AESEnc.Key(KeyCharArr);
AESEnc.Padding(cPadding.Zeros);
cEnc := AESEnc.CreateEncryptor;
cMode := cMode.Write;
dStream := dStream.MemoryStream();
cStream := cStream.CryptoStream(dStream, cEnc, cMode);
sWriter := sWriter.StreamWriter(cStream);
sWriter.AutoFlush(TRUE);
sWriter.Write(SourceString);
cStream.FlushFinalBlock;
sWriter.Close;
dBytes := dStream.GetBuffer();
TargetString := dConvert.ToBase64String(dBytes);
MESSAGE('Encrypted = %1', TargetString);
4. November 2014 09:56
4. November 2014 20:50
10. Juli 2015 12:25