ここにあるDCPcrypt ライブラリを使用しています。
これは、文字列を暗号化するための小さなコードです
InitializationVector: AnsiString;
const Key: Ansistring = 'keykeykeykey';
// Encrypt a string and return the Base64 encoded result
function Encrypt(DataToEncrypt: ansistring):ansistring;
var
Cipher : TDCP_rijndael;
Data: string;
IV: array[0..15] of byte; // the initialization vector
i:Integer;
begin
// Pad Key, IV and Data with zeros as appropriate
FillChar(IV,Sizeof(IV),0); // make the IV all zeros
Data := PadWithZeros(DataToEncrypt,BlockSize);
for i := 0 to (Length(IV) - 1) do //just random values for the IV
IV[i] := Random(256);
Cipher := TDCP_rijndael.Create(nil);
if Length(Key) <= 16 then
Cipher.Init(Key[1],128,@IV[1])
else if Length(Key) <= 24 then
Cipher.Init(Key[1],192,@IV[1])
else
Cipher.Init(Key[1],256,@IV[1]);
// Encrypt the data
Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
// Free the cipher and clear sensitive information
Cipher.Free;
SetString(InitializationVector,PAnsiChar(@IV[1]),Length(IV));
InitializationVector := Base64EncodeStr(InitializationVector);
//Base64 encoded result
Result := Base64EncodeStr(Data);
end;
結果の文字列を復号化できますが、半分しかありません。同様の投稿が1つ見つかりましたが、私がやっているbase64で暗号文をエンコードするときに答えを見つけました。ここに。
どんな助けでも大歓迎です!