http - Web 応答にデジタル署名しようとしています。基本的に、HTML とマルチパート コンテンツ タイプの応答を作成し、応答に署名してから、デジタル署名を応答に追加します。追加された署名は実際には HEXtoString であるため、これは真の PGP 署名ではないため、私は近いと思いますが、いくつかのステップから外れています。大きなことは、応答を正しく解釈できるように、署名を正しく表現できることです。私はこれにかなり慣れているので、ここでいくつかの提案を使用できます。よろしくお願いします..以下は、私が現在使用しているコードのスニペットです。
StringBuffer myResponse = new StringBuffer("");
myResponse.append(getHttpHeader());
KeyPair pair2 = loadKeyPair();//loads a key pair from generated files
if (signer==null)
signer = Signature.getInstance("MD5withRSA");
signer.initSign(pair2.getPrivate());
signer.update(message.getBytes());
byte[] b = signer.sign();
FileOutputStream sigfos = new FileOutputStream(getFileLocation(0,localTest));
sigfos.write(b);
sigfos.close();
//verify
signer.initVerify(pair2.getPublic());//pubKey);
signer.update(message.getBytes());
if (signer.verify(b)){
myResponse.append(message);
}
StringBuffer signed= new StringBuffer("");
signed.append(boundary);
signed.append(CRLF);
signed.append("content-type: application/pgp-signature");
signed.append(CRLF);
signed.append("-----BEGIN PGP MESSAGE-----");
signed.append(CRLF);
signed.append("Version: 1");//update this
signed.append(CRLF);
signed.append(CRLF);
signed.append(digSignature);//generated as HexString representation of signed file from above
signed.append(CRLF);
signed.append("-----END PGP MESSAGE-----");
signed.append(CRLF);
signed.append(boundary+"--");
myResponse.append (signed);
ServletOutputStream.println(myResponse);
結果として送信される「署名」は、署名されたファイルのバイトハッシュ hexToString 表現です。私は標準の Java クラスを使用していますが、他のライブラリが 0-9a-f 表現以外の文字を含む真の PGP 表現を提供してくれるかどうかはわかりません。アイデア??