下面给出的代码是否有等效的加密程序。 当前的实现不支持加密,并且不支持“#39;功能”。异常。
以下例程成功解密了此密码' G6DR0607ZXRu24envBxPRA =='其纯文本值' 1'。我需要反转这个过程并得到相同的给定密码。
我希望有人可以使用DecryptAES256例程中的相同步骤帮助我提供加密明文值的工作等效代码。
const
Key: array of byte = [$61,$A6,$02,$D1,$E6,$89,$87,$A3,$7C,$0B,$54,$D2,$64,$7D,
$B9,$41,$D0,$E6,$56,$DE,$CF,$A2,$5B,$6C,$76,$4A,$BB,$FA,
$DB,$CD,$41,$2D];
IV: array of byte = [$86,$78,$1C,$D2,$66,$91,$F7,$91,$3B,$2A,$44,$10,$DF,$38,
$E4,$47];
function DecryptAES256(const Value: String): String;
var
Codec: TCodec;
CryptographicLibrary: TCryptographicLibrary;
CipherStream, PlainTextStream: TStream;
buffer: array of Byte;
begin
Codec := TCodec.Create( nil);
CryptographicLibrary := TCryptographicLibrary.Create( nil);
CipherStream := TMemoryStream.Create;
PlainTextStream := TMemoryStream.Create;
try
Codec.CryptoLibrary := CryptographicLibrary;
CryptographicLibrary.RegisterStreamCipher(StreamToBlock_Adapter_CSharpVariant);
Codec.StreamCipherId := 'CSharp.StreamToBlock';
Codec.BlockCipherId := Format( AES_ProgId, [256]);
Codec.AsymetricKeySizeInBits := 256;
Codec.Cipher := '[AES-256*]';
Codec.ChainModeId := CBC_ProgId;
CipherStream.WriteBuffer( Key[0], Length(Key));
CipherStream.Position := 0;
Codec.InitFromStream(CipherStream);
CipherStream.Size := 0;
CipherStream.WriteBuffer( IV[0], Length(IV));
Base64_to_stream(Value, CipherStream);
CipherStream.Position := 0;
Codec.DecryptStream(PlainTextStream, CipherStream);
PlainTextStream.Position := 0;
SetLength(buffer, PlainTextStream.Size);
PlainTextStream.ReadBuffer(buffer[0], Length(buffer));
Result := StripNonAscii(ByteToString(buffer));
finally
CipherStream.Free;
PlainTextStream.Free;
Codec.Free;
CryptographicLibrary.Free;
end;
end;