我與RC4加密證書的文件, 這件作品的負責寫這樣的證書對文件代碼如下:在Perl中,同時使用RC4我無法找回密文
sub dummyFunction() {
# Useless stuff for the scope of the problem
# ...
my $dbHost = "localhost";
my $passphrase = "123"; # For example purposes, logic is different.
my $cipher = Crypt::RC4->new($passphrase);
return unpack('H*',$cipher->RC4($dbHost));
}
所以這段代碼會返回類似:3F9FDCE3891C6B8851
,但如果我嘗試以下方法:
sub anotherDummyFunction() {
my $ciphered_text = &dummyFunction();
my $passphrase = "123";
my $cipher = Crypt::RC4->new($passphrase);
print $cipher->RC4(pack('H*',$ciphered_text));
}
我期待看到localhost
但相反,我得到了一堆字節,所以我會怎麼弄回原文?
我已經在線檢查了一個RC4解密器,用我的密碼和我的十六進制編碼的字符串和RC4在線解密器確實返回localhost
,所以我確信加密的字符串是正確的。
謝謝!
P.S.:上面的例子在一個孤立的環境中工作,但是當涉及到我的腳本時,它不會。我無法取回原始字符串。
請勿向我們展示可用的示例代碼,並告訴我們它在某些其他上下文中不起作用。我們唯一知道的是,在你向我們展示的任何東西中,問題*都不是。 – hobbs
我將使用我的心理調試技巧來說明在你的實際腳本中有一些空白已經進入'$ ciphered_text'。 'pack('H *',$ ciphered_text)'不會**只打包十六進制數字;它抓取'$ ciphered_text'中每個字符的低4位,包括空格字符。 – cjm
我已經找到問題的根源。起初我以爲這是一個空白,但事實並非如此。 我之前正在加密另一個字符串,但那個正在被正確加密。 我有一個頓悟,我認爲RC4可以緩存的東西,所以我undef它,它的工作。 – ILikeTacos