<%@ page language="java" contentType="text/html; charset=UTF-8" %> <%@ page import="yss.iothe.pdftimestamp.PdfTimeStampException" %> <%@ page import="yss.iothe.pdftimestamp.PdfTimeStampFactory" %> <%@ page import="yss.iothe.pdftimestamp.PdfTimeStampService" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.HASH_ALGORITHM" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_128_ACCESSBILITY" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_128_CHANGE" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_128_COPY" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_128_PRINT" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_40_ADDNOTE" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_40_COPY" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_40_EDIT" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.PDF_SECURITY_40_PRINT" %> <%@ page import="yss.iothe.pdftimestamp.com.PdfTimeStampConst.POLICY" %> <%@ page import="yss.iothe.pdftimestamp.info.PdfDocument" %> <%@ page import="yss.iothe.pdftimestamp.info.PdfTimeStamp" %> <%@ page import="yss.iothe.pdftimestamp.info.PdfTimeStampToken" %> <%@ page import="java.util.Date" %> <%! /** * PDFタイムスタンプインスタンス生成 * URLが未指定であればスタンドアロン環境、 * URLが指定されていれば分散環境として処理を行う。 * URLは下記の形式で指定する。 * 「http://{IPアドレスおよびポート番号}/pdftimestamp/webapi/timestamp」 */ private static PdfTimeStampService service = PdfTimeStampFactory.createPdfTimeStampService(); /* private static PdfTimeStampService service = PdfTimeStampFactory.createPdfTimeStampService( "http://xxxxxxxx:xxxx/pdftimestamp/webapi/timestamp", 30, 600); */ /***************************************** * 処理ファイル設定 *****************************************/ /* 処理対象PDFファイルパス */ private static final String inputpdfpath = "C:/temp/in.pdf"; /* 処理対象PDF権限パスワード */ private static final String inputpdfpasswd = "security"; /* 処理結果PDF出力先ファイルパス1 */ private static final String outpdfpath1 = "C:/temp/out.1.pdf"; /* 処理結果PDF出力先ファイルパス2 */ private static final String outpdfpath2 = "C:/temp/out.2.pdf"; /***************************************** * タイムスタンプトークン取得設定 *****************************************/ /* ハッシュアルゴリズム */ private static final HASH_ALGORITHM alg = HASH_ALGORITHM.SHA512; /* ポリシー */ private static final POLICY policy = POLICY.TYPEA2; /***************************************** * タイムスタンプ局の設定 *****************************************/ /* タイムスタンプ局の接続先のURL */ private static final String tsaurl = "https://timestamp.seiko-cybertime.jp/basic/Timestamp?type=AccreditedA2"; /* タイムスタンプ局接続時の接続ID */ private static final String tsauser = "xxxxxxxx@xxxx.xx.xx"; /* タイムスタンプ局接続時のパスワード */ private static final String tsapasswd = "xxxxxxxx"; /***************************************** * セキュリティ設定 *****************************************/ /* 処理結果PDFファイルに付与する参照パスワード */ private static final String openpasswd = "open"; /* 処理結果PDFファイルに付与するセキュリティパスワード */ private static final String secpasswd = "security"; /***************************************** * 処理結果PDFファイルに付与する * RC4 40bitセキュリティ設定 *****************************************/ /* 印刷許可 */ private static final PDF_SECURITY_40_PRINT security40_print = PDF_SECURITY_40_PRINT.DISABLE; /* 編集許可 */ private static final PDF_SECURITY_40_EDIT security40_edit = PDF_SECURITY_40_EDIT.ENABLE; /* コピー許可 */ private static final PDF_SECURITY_40_COPY security40_copy = PDF_SECURITY_40_COPY.DISABLE; /* 注釈追記許可 */ private static final PDF_SECURITY_40_ADDNOTE security40_addnote = PDF_SECURITY_40_ADDNOTE.DISABLE; /***************************************** * 処理結果PDFファイルに付与する * RC4 1280bitセキュリティ設定 *****************************************/ /* 印刷許可 */ private static final PDF_SECURITY_128_PRINT security128_print = PDF_SECURITY_128_PRINT.ENABLE; /* アクセス許可 */ private static final PDF_SECURITY_128_ACCESSBILITY security128_access = PDF_SECURITY_128_ACCESSBILITY.ENABLE; /* 印刷許可 */ private static final PDF_SECURITY_128_COPY security128_copy = PDF_SECURITY_128_COPY.ENABLE; /* 文書変更許可 */ private static final PDF_SECURITY_128_CHANGE security128_change = PDF_SECURITY_128_CHANGE.ENABLE; %> IM-PDFTimeStamperサンプル
文書タイムスタンプ付与
<%= addTimestamp() %>
延長タイムスタンプ付与
<%= extendTimestamp() %>
PDF文書のタイムスタンプ検証(validate)
<%= validateTimestamp() %>
PDF文書のタイムスタンプ検証(validateTs)
<%= validateTsTimestamp() %>
PDF文書の情報取得
<%= getInfo() %>
<%! /** * 文書タイムスタンプの付与 */ String addTimestamp() { StringBuffer resultBuffer = new StringBuffer(200); /* PDF情報 */ PdfDocument docinfo; try { /***************************************** * 実行準備 *****************************************/ /* 文書タイムスタンプを付与するPDFファイルのパス、及び権限パスワードを設定 */ service.setInputPdf(inputpdfpath, inputpdfpasswd); /* 処理結果PDF出力先パスを設定 */ service.setOutputPdf(outpdfpath1); /* タイムスタンプトークン取得用のハッシュアルゴリズムを設定 */ service.setHashAlgorithm(alg); /* タイムスタンプトークン取得用のポリシーを設定 */ service.setPolicy(policy); /* タイムスタンプ局の接続先のURLを設定 */ service.setTsaUrl(tsaurl); /* タイムスタンプ局接続時の接続ID、パスワードを設定 */ service.setTsaUser(tsauser, tsapasswd); /* 出力PDFのセキュリティ設定(40/128のどちらかを指定) */ /* service.setSecurity40(openpasswd, secpasswd, security40_print, security40_edit, security40_copy, security40_addnote); */ service.setSecurity128(openpasswd, secpasswd, security128_print, security128_access, security128_copy, security128_change); /***************************************** * 実行 *****************************************/ /* PDFに対し文書タイムスタンプを付与 */ service.generate(); resultBuffer.append("addTimestamp : SUCCESS
"); /***************************************** * 実行 *****************************************/ /* PDFおよびタイムスタンプ情報の取得 */ docinfo = service.getPdfDocument(); /***************************************** * 取得情報出力:PDFドキュメント情報 *****************************************/ /* ファイルサイズの取得 */ long fileSize = docinfo.getContentSize(); resultBuffer.append("File Size: " + fileSize + " Bytes
"); /* ページ数の取得 */ int pageNum = docinfo.getNumberOfPages(); resultBuffer.append("Page Num: " + pageNum + " Pages
"); /* ページサイズ(幅)の取得 */ double paperWidth = docinfo.getPaperWidth(); resultBuffer.append("Page Width: " + paperWidth + " pts
"); /* ページサイズ(高さ)の取得 */ double paperHeight = docinfo.getPaperHeight(); resultBuffer.append("Page Height: " + paperHeight + " pts
"); /* 解像度取得 */ int resolution = docinfo.getResolution(); resultBuffer.append("Resolution: " + resolution + " dpi
"); /* 解像度取得 */ int gradation = docinfo.getGradation(); resultBuffer.append("Gradation: " + gradation + "
"); /* 最新のタイムスタンプ情報の取得 */ // PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp(); /* タイムスタンプリストの取得 */ PdfTimeStamp[] timeStampList = docinfo.getTimeStamps(); resultBuffer.append("TimeStamp Length: " + timeStampList.length + "
"); /* VRI付きタイムスタンプリストの取得 */ PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI(); if (vriTimeStampList != null) { resultBuffer.append("VRI TimeStamp Length: " + vriTimeStampList.length + "
"); } /* VRI付きでないタイムスタンプリストの取得 */ PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI(); if (notVriTimeStampList != null) { resultBuffer.append("NotVRI TimeStamp Length: " + notVriTimeStampList.length + "
"); } /***************************************** * 取得情報出力:タイムスタンプ情報 *****************************************/ for (int i = 0; i < timeStampList.length; i++) { resultBuffer.append("TimeStamp[" + i + "]
"); /* ハッシュアルゴリズムの取得 */ HASH_ALGORITHM hashAlgorithm = timeStampList[i] .getHashAlgorithm(); resultBuffer.append("HashAlgorithm: " + hashAlgorithm + "
"); /* 有効期限の取得 */ Date expirationDate = timeStampList[i] .getTimeStampExpirationDate(); resultBuffer.append("ExpirationDate: " + expirationDate + "
"); /* タイムスタンプ生成日時の取得 */ Date createDate = timeStampList[i].getCreationDate(); resultBuffer.append("CreateDate: " + createDate + "
"); /* 検証結果の取得 */ int validateResult = timeStampList[i].getValidateResult(); resultBuffer.append("validateResult: " + validateResult + "
"); /* 署名Vriが付加されているかの取得 */ boolean vriFlg = timeStampList[i].getVriFlg(); resultBuffer.append("vriFlg: " + vriFlg + "
"); /* タイムスタンプ情報の取得 */ PdfTimeStampToken token = timeStampList[i].getTimeStampToken(); /***************************************** * 取得情報出力:タイムスタンプトークン *****************************************/ /* タイムスタンプデータ値の取得 */ byte[] tokenData = token.getData(); resultBuffer.append("Token Data: " + tokenData + "
"); /* 登録時のタイムスタンプハッシュ値の取得 */ byte[] registerDigest = token.getRegisterDigest(); resultBuffer.append("Token RegisterDigest: " + registerDigest + "
"); /* 検証時のタイムスタンプハッシュ値の取得 */ byte[] digest = token.getDigest(); resultBuffer.append("Token Digest: " + digest + "
"); } } catch (PdfTimeStampException e) { resultBuffer.append("addTimestamp : ERROR
"); resultBuffer.append("status : " + e.getCode() + ", message : "+ e.getMessage() + "
"); } finally { } return resultBuffer.toString(); } /** * 延長タイムスタンプの付与 */ String extendTimestamp() { StringBuffer resultBuffer = new StringBuffer(200); /* PDF情報 */ PdfDocument docinfo; try { /***************************************** * 実行準備 *****************************************/ /* 延長タイムスタンプを付与するPDFファイルのパス、及び権限パスワードを設定 */ service.setInputPdf(outpdfpath1, inputpdfpasswd); /* 処理結果PDF出力先パスを設定 */ service.setOutputPdf(outpdfpath2); /* タイムスタンプトークン取得用のハッシュアルゴリズムを設定 */ service.setHashAlgorithm(alg); /* タイムスタンプトークン取得用のポリシーを設定 */ service.setPolicy(policy); /* タイムスタンプ局の接続先のURLを設定 */ service.setTsaUrl(tsaurl); /* タイムスタンプ局接続時の接続ID、パスワードを設定 */ service.setTsaUser(tsauser, tsapasswd); /***************************************** * 実行 *****************************************/ /* PDFに対し文書タイムスタンプを付与 */ service.generateLtv(); /***************************************** * 実行結果出力 *****************************************/ resultBuffer.append("extendTimestamp : SUCCESS
"); /***************************************** * 実行 *****************************************/ /* PDFおよびタイムスタンプ情報の取得 */ docinfo = service.getPdfDocument(); /***************************************** * 取得情報出力:PDFドキュメント情報 *****************************************/ /* ファイルサイズの取得 */ long fileSize = docinfo.getContentSize(); resultBuffer.append("File Size: " + fileSize + " Bytes
"); /* ページ数の取得 */ int pageNum = docinfo.getNumberOfPages(); resultBuffer.append("Page Num: " + pageNum + " Pages
"); /* ページサイズ(幅)の取得 */ double paperWidth = docinfo.getPaperWidth(); resultBuffer.append("Page Width: " + paperWidth + " pts
"); /* ページサイズ(高さ)の取得 */ double paperHeight = docinfo.getPaperHeight(); resultBuffer.append("Page Height: " + paperHeight + " pts
"); /* 解像度取得 */ int resolution = docinfo.getResolution(); resultBuffer.append("Resolution: " + resolution + " dpi
"); /* 解像度取得 */ int gradation = docinfo.getGradation(); resultBuffer.append("Gradation: " + gradation + "
"); /* 最新のタイムスタンプ情報の取得 */ // PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp(); /* タイムスタンプリストの取得 */ PdfTimeStamp[] timeStampList = docinfo.getTimeStamps(); resultBuffer.append("TimeStamp Length: " + timeStampList.length + "
"); /* VRI付きタイムスタンプリストの取得 */ PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI(); if (vriTimeStampList != null) { resultBuffer.append("VRI TimeStamp Length: " + vriTimeStampList.length + "
"); } /* VRI付きでないタイムスタンプリストの取得 */ PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI(); if (notVriTimeStampList != null) { resultBuffer.append("NotVRI TimeStamp Length: " + notVriTimeStampList.length + "
"); } /***************************************** * 取得情報出力:タイムスタンプ情報 *****************************************/ for (int i = 0; i < timeStampList.length; i++) { resultBuffer.append("TimeStamp[" + i + "]
"); /* ハッシュアルゴリズムの取得 */ HASH_ALGORITHM hashAlgorithm = timeStampList[i] .getHashAlgorithm(); resultBuffer.append("HashAlgorithm: " + hashAlgorithm + "
"); /* 有効期限の取得 */ Date expirationDate = timeStampList[i] .getTimeStampExpirationDate(); resultBuffer.append("ExpirationDate: " + expirationDate + "
"); /* タイムスタンプ生成日時の取得 */ Date createDate = timeStampList[i].getCreationDate(); resultBuffer.append("CreateDate: " + createDate + "
"); /* 検証結果の取得 */ int validateResult = timeStampList[i].getValidateResult(); resultBuffer.append("validateResult: " + validateResult + "
"); /* 署名Vriが付加されているかの取得 */ boolean vriFlg = timeStampList[i].getVriFlg(); resultBuffer.append("vriFlg: " + vriFlg + "
"); /* タイムスタンプ情報の取得 */ PdfTimeStampToken token = timeStampList[i].getTimeStampToken(); /***************************************** * 取得情報出力:タイムスタンプトークン *****************************************/ /* タイムスタンプデータ値の取得 */ byte[] tokenData = token.getData(); resultBuffer.append("Token Data: " + tokenData + "
"); /* 登録時のタイムスタンプハッシュ値の取得 */ byte[] registerDigest = token.getRegisterDigest(); resultBuffer.append("Token RegisterDigest: " + registerDigest + "
"); /* 検証時のタイムスタンプハッシュ値の取得 */ byte[] digest = token.getDigest(); resultBuffer.append("Token Digest: " + digest + "
"); } } catch (PdfTimeStampException e) { resultBuffer.append("extendTimestamp : ERROR
"); resultBuffer.append("status : " + e.getCode() + ", message : " + e.getMessage() + "
"); } finally{ } return resultBuffer.toString(); } /** * タイムスタンプの検証 */ String validateTimestamp() { StringBuffer resultBuffer = new StringBuffer(200); /* 検証結果 */ int res; try { /***************************************** * 実行準備 *****************************************/ /* タイムスタンプを検証するPDFファイルのパス、及び権限パスワードを設定 */ service.setInputPdf(outpdfpath2, inputpdfpasswd); /***************************************** * 実行 *****************************************/ /* PDFのタイムスタンプを検証 */ res = service.validate(); /***************************************** * 実行結果出力 *****************************************/ resultBuffer.append("validateTimestamp : SUCCESS : [" + res + "]
"); } catch (PdfTimeStampException e) { resultBuffer.append("validateTimestamp : ERROR
"); resultBuffer.append("status : " + e.getCode() + ", message : " + e.getMessage() + "
"); } finally{ } return resultBuffer.toString(); } String validateTsTimestamp() { StringBuffer resultBuffer = new StringBuffer(200); /* 検証結果 */ PdfTimeStamp[] timeStampList; try { /***************************************** * 実行準備 *****************************************/ /* タイムスタンプを検証するPDFファイルのパス、及び権限パスワードを設定 */ service.setInputPdf(outpdfpath2, inputpdfpasswd); /***************************************** * 実行 *****************************************/ /* PDFのタイムスタンプを検証 */ timeStampList = service.validateTs(); /***************************************** * 取得情報出力:タイムスタンプ情報 *****************************************/ for (int i = 0; i < timeStampList.length; i++) { resultBuffer.append("TimeStamp[" + i + "]
"); /* ハッシュアルゴリズムの取得 */ HASH_ALGORITHM hashAlgorithm = timeStampList[i] .getHashAlgorithm(); resultBuffer.append("HashAlgorithm: " + hashAlgorithm + "
"); /* 有効期限の取得 */ Date expirationDate = timeStampList[i] .getTimeStampExpirationDate(); resultBuffer.append("ExpirationDate: " + expirationDate + "
"); /* タイムスタンプ生成日時の取得 */ Date createDate = timeStampList[i].getCreationDate(); resultBuffer.append("CreateDate: " + createDate + "
"); /* 検証結果の取得 */ int validateResult = timeStampList[i].getValidateResult(); resultBuffer.append("validateResult: " + validateResult + "
"); /* 署名Vriが付加されているかの取得 */ boolean vriFlg = timeStampList[i].getVriFlg(); resultBuffer.append("vriFlg: " + vriFlg + "
"); /* タイムスタンプ情報の取得 */ PdfTimeStampToken token = timeStampList[i].getTimeStampToken(); /***************************************** * 取得情報出力:タイムスタンプトークン *****************************************/ /* タイムスタンプデータ値の取得 */ byte[] tokenData = token.getData(); resultBuffer.append("Token Data: " + tokenData + "
"); /* 登録時のタイムスタンプハッシュ値の取得 */ byte[] registerDigest = token.getRegisterDigest(); resultBuffer.append("Token RegisterDigest: " + registerDigest + "
"); /* 検証時のタイムスタンプハッシュ値の取得 */ byte[] digest = token.getDigest(); resultBuffer.append("Token Digest: " + digest + "
"); } } catch (PdfTimeStampException e) { resultBuffer.append("validateTsTimestamp : ERROR
"); resultBuffer.append("status : " + e.getCode() + ", message : " + e.getMessage() + "
"); } finally{ } return resultBuffer.toString(); } /** * PDFドキュメント、及びタイムスタンプ情報の取得 */ String getInfo() { StringBuffer resultBuffer = new StringBuffer(200); /* PDF情報 */ PdfDocument docinfo; try { /***************************************** * 実行準備 *****************************************/ /* 情報を取得するPDFファイルのパス、及び権限パスワードを設定 */ service.setInputPdf(outpdfpath2, inputpdfpasswd); /***************************************** * 実行 *****************************************/ /* PDFおよびタイムスタンプ情報の取得 */ docinfo = service.getPdfDocument(); /***************************************** * 取得情報出力:PDFドキュメント情報 *****************************************/ /* ファイルサイズの取得 */ long fileSize = docinfo.getContentSize(); resultBuffer.append("File Size: " + fileSize + " Bytes
"); /* ページ数の取得 */ int pageNum = docinfo.getNumberOfPages(); resultBuffer.append("Page Num: " + pageNum + " Pages
"); /* ページサイズ(幅)の取得 */ double paperWidth = docinfo.getPaperWidth(); resultBuffer.append("Page Width: " + paperWidth + " pts
"); /* ページサイズ(高さ)の取得 */ double paperHeight = docinfo.getPaperHeight(); resultBuffer.append("Page Height: " + paperHeight + " pts
"); /* 解像度取得 */ int resolution = docinfo.getResolution(); resultBuffer.append("Resolution: " + resolution + " dpi
"); /* 解像度取得 */ int gradation = docinfo.getGradation(); resultBuffer.append("Gradation: " + gradation + "
"); /* 最新のタイムスタンプ情報の取得 */ //PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp(); /* タイムスタンプリストの取得 */ PdfTimeStamp[] timeStampList = docinfo.getTimeStamps(); /* タイムスタンプが付与されていない場合は処理終了 */ if (timeStampList == null) { resultBuffer.append("タイムスタンプが付与されていません。
"); resultBuffer.append("getInfo : SUCCESS
"); return resultBuffer.toString(); } /* 付与されているタイムスタンプを出力 */ resultBuffer.append("TimeStamp Length: " + timeStampList.length + "
"); /* VRI付きタイムスタンプリストの取得 */ PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI(); if (vriTimeStampList != null) { resultBuffer.append("VRI TimeStamp Length: " + vriTimeStampList.length + "
"); } /* VRI付きでないタイムスタンプリストの取得 */ PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI(); if (notVriTimeStampList != null) { resultBuffer.append("NotVRI TimeStamp Length: " + notVriTimeStampList.length + "
"); } /***************************************** * 取得情報出力:タイムスタンプ情報 *****************************************/ for (int i = 0; i < timeStampList.length; i++) { resultBuffer.append("TimeStamp[" + i + "]
"); /* ハッシュアルゴリズムの取得 */ HASH_ALGORITHM hashAlgorithm = timeStampList[i] .getHashAlgorithm(); resultBuffer.append("HashAlgorithm: " + hashAlgorithm + "
"); /* 有効期限の取得 */ Date expirationDate = timeStampList[i] .getTimeStampExpirationDate(); resultBuffer.append("ExpirationDate: " + expirationDate + "
"); /* タイムスタンプ生成日時の取得 */ Date createDate = timeStampList[i].getCreationDate(); resultBuffer.append("CreateDate: " + createDate + "
"); /* 検証結果の取得 */ int validateResult = timeStampList[i].getValidateResult(); resultBuffer.append("validateResult: " + validateResult + "
"); /* 署名Vriが付加されているかの取得 */ boolean vriFlg = timeStampList[i].getVriFlg(); resultBuffer.append("vriFlg: " + vriFlg + "
"); /* タイムスタンプ情報の取得 */ PdfTimeStampToken token = timeStampList[i].getTimeStampToken(); /***************************************** * 取得情報出力:タイムスタンプトークン *****************************************/ /* タイムスタンプデータ値の取得 */ byte[] tokenData = token.getData(); resultBuffer.append("Token Data: " + tokenData + "
"); /* 登録時のタイムスタンプハッシュ値の取得 */ byte[] registerDigest = token.getRegisterDigest(); resultBuffer.append("Token RegisterDigest: " + registerDigest + "
"); /* 検証時のタイムスタンプハッシュ値の取得 */ byte[] digest = token.getDigest(); resultBuffer.append("Token Digest: " + digest + "
"); } /***************************************** * 実行結果出力 *****************************************/ resultBuffer.append("getInfo : SUCCESS
"); } catch (PdfTimeStampException e) { resultBuffer.append("getInfo : ERROR
"); resultBuffer.append("status : " + e.getCode() + ", message : " + e.getMessage() + "
"); } finally{ } return resultBuffer.toString(); } %>