私は現在、PHP を使用して S/Mime 復号化を実現しています。私がこれまでに得たもの:
$keys = array("public"=>$atm."/public-keys/".$usr.".smime",
"private"=>$atm."/private-keys/".$usr.".smime");
if(!file_exists($keys["public"])) die("Public Key not found");
if(!file_exists($keys["private"])) die("Private Key not found");
$public = file_get_contents($keys["public"]);
$private = file_get_contents($keys["private"]);
switch($_GET["debug"])
{
case "encrypt":
{
$outfile = realpath("demo-msg/out.txt");
$outfile_signed = realpath("demo-msg/out.signed.txt");
$infile = realpath("demo-msg/in.txt");
file_put_contents($infile,$msg);
$adddata = array("To" => "XXX", "From: Demo Name <XXX>", "Subject" => "Demo Subject");
if (openssl_pkcs7_encrypt($infile, $outfile, $public, $adddata))
{
//$info = file_get_contents($outfile);
echo "winenc & transfer<br>\n";
file_put_contents($infile, file_get_contents($outfile));
//if(openssl_pkcs7_sign($outfile,$outfile_signed,$public,$private,$adddata, PKCS7_BINARY)) echo "winsign";
//else echo "failsign";
}
else echo "Failed Encryption";
exit;
}
default:
{
$outfile2 = realpath("demo-msg/out2.txt");
$outfile = realpath("demo-msg/out.txt");
$infile = realpath("demo-msg/smime.p7m");
//$infile = realpath("demo-msg/in.txt");
if(openssl_pkcs7_verify($infile)) echo "verified<br>\n"; //tried: openssl_pkcs7_verify($infile,$PKCS7_DETACHED, tmpfile(), array(), array(), $outfile)
else die("invalid sig");
if(openssl_pkcs7_decrypt($infile, $outfile2, $public, $private)) //tried: openssl_pkcs7_decrypt($outfile, $outfile2, $public, $private)
{
echo "dec win:".file_get_contents($outfile2);
}
else echo "Oh oh! Decryption failed!";
exit;
}
}
このスニペットですでにできること:
- メッセージを暗号化する
- 暗号化されたメッセージを復号化する (自分で作成した)
- 署名されていない限り、暗号化されたメッセージを復号化する (Office 2010)
ここで、署名されたメッセージも解読したいと思います (通常は 1 つのステップであるため)。問題:
- 最初に復号化を試みると、暗号化されたメッセージが異なるヘッダーで返されます。複数の復号化は同じ結果につながります。
- 私の考えでは、検証の $content - パラメータ - コマンド (openssl_pkcs7_verify) を使用していました。コードコメントで私の試みを見ることができます。
それにもかかわらず、2回目の試行で何が問題になるかについての手がかりはありません。任意の助けをいただければ幸いです!