私は IV (初期化ベクトル) と鍵、および暗号文を持っています。暗号文を解読する必要があります。インターネットからDCPcrypt Cryptographic Component Library v2を見つけました。だから、今私はコーディングに到達しました。
procedure TForm1.Button1Click(Sender: TObject);
var
key:Ansistring;
ivector,indata,outdata:string;
begin
key := 'abc12345679'; //<--key for decrypting
dcp_rijndael1.InitStr(key,TDCP_sha1); //I don't understand why i need hashing!?
ivector := edit2.Text; //initialization vector
dcp_rijndael1.SetIV(ivector);
dcp_rijndael1.BlockSize := Length(ivector); //'This variable should be the same size as the block size' says the documentation
indata := edit1.Text; //getting the cryptogram
dcp_rijndael1.CipherMode := cmCBC;
dcp_rijndael1.DecryptCBC(indata,outdata,Length(indata));
label3.Caption := outdata; //output to label
end;
このコードでエラーが発生します。[ローカル変数] ウィンドウに、indata、outdata、ivector、キー変数が「アクセスできない値」として表示されます。または、それを行う別の方法があるかもしれません。ただし、これはかなり簡単に思えます。前もって感謝します。
Wodzu のヘルプの後: base64 でエンコードされた復号化された文字列を受け取ったことに注意してください。最初にそれをデコードする必要があると思います。
var
Form1: TForm1;
StringToEncrypt, StringToDecrypt, DecryptedString: string;
vector:string;
procedure TForm1.Button2Click(Sender: TObject);
begin
vector := '1234567812345678'; //Length 16
stringtodecrypt := '2YOXZ20Z7B3TRI/Ut8iH/GpEZWboE2tnnWU';
stringtodecrypt := Decode64(stringtodecrypt); //after encrypted string is sent over internet, it is encoded with base64, so i need to decode it.
SetLength(DecryptedString, 36); //36 is the length of the output
DCP_rijndael1.Init('MyKey:128bit', 128, @Vector[1]);
DCP_rijndael1.SetIV(Vector);
DCP_rijndael1.BlockSize := Length(Vector); //Should this be also 128
DCP_rijndael1.DecryptCBC(StringToDecrypt[1], DecryptedString[1], Length(StringToDecrypt)*2); //Here i get hieroglyph as a result. Why is length multiplied with 2?
decryptedstring := Encode64(decryptedstring); //Here i get less hieroglyph, but would like to get correct decrypted string. I doubt the necessity of encoding
ShowMessage(DecryptedString);
end;
このコードを作成して、他の誰かが (PHP で) 暗号化しているデータを復号化することはできません (暗号化後、データは base64 でエンコードされます)。 ノート!暗号化されたテキストの長さは、復号化されたテキストの長さと同じではありません!