チュートリアル¶
前提条件¶
本項では、 IM-PDFTimeStamper for Accel Platform での開発の導入として、APIを利用したPDFファイルへのタイムスタンプ付与処理を作成することによって、 IM-PDFTimeStamper for Accel Platform での開発の流れを体験します。
本項のチュートリアルを開始するにあたっての前提条件は、次の通りです。
- intra-mart Accel Platform 、および、 IM-PDFTimeStamper for Accel Platform が正しくセットアップされていること
- セイコーソリューションズ株式会社のセイコータイムスタンプサービスの契約が完了していること
ここでは、 JavaEE開発モデル の開発の流れを説明します。
用語解説¶
- Resin をインストールしたディレクトリを %RESIN_HOME% と略します。
- Apache HTTP Server をインストールしたディレクトリを %APACHE_HOME% と略します。
- Storage として使用するディレクトリを %PUBLIC_STORAGE_PATH% と略します。
- Webサーバ利用時の静的コンテンツを配置するディレクトリを %WEB_PATH% と略します。
準備¶
タイムスタンプを付与するPDFファイルを「 in.pdf 」のファイル名で作成し、 intra-mart Accel Platform サーバの< C:/temp >ディレクトリに配置してください。
JSPプログラムの作成¶
テキストエディタを使用してJSPファイルを作成します。
Resin の場合、< %RESIN_HOME%/webapps/warファイルと同名のディレクトリ/ >の配下に、「 PdfTimeStampSample.jsp 」の名前でファイルを作成し、次のソースを実装します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | <%@ 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" %>
<%@ taglib prefix="imui" uri="http://www.intra-mart.co.jp/taglib/imui" %>
<%!
/**
* 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;
%>
<imui:head>
<title>IM-PDFTimeStamper-チュートリアル-JavaEE開発モデル-TimeStamp</title>
</imui:head>
<div class="imui-title">
<h1>IM-PDFTimeStamper チュートリアル JavaEE開発モデル TimeStamp</h1>
</div>
<div class="imui-form-container">
<div class="imui-chapter-title"><h2>実行結果</h2></div>
<form>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-225px">文書タイムスタンプ付与</th>
<td><%= addTimestamp() %></td>
</tr>
</tbody>
</table>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-225px">延長タイムスタンプ付与</th>
<td><%= extendTimestamp() %></td>
</tr>
</tbody>
</table>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-225px">PDF文書のタイムスタンプ検証(validate)</th>
<td><%= validateTimestamp() %></td>
</tr>
</tbody>
</table>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-225px">PDF文書のタイムスタンプ検証(validateTs)</th>
<td><%= validateTsTimestamp() %></td>
</tr>
</tbody>
</table>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-225px">PDF文書の情報取得</th>
<td><%= getInfo() %></td>
</tr>
</tbody>
</table>
</form>
</div>
<%!
/**
* 文書タイムスタンプの付与
*/
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("文書タイムスタンプ付与:SUCCESS<br>");
/*****************************************
* 実行
*****************************************/
/* PDFおよびタイムスタンプ情報の取得 */
docinfo = service.getPdfDocument();
/*****************************************
* 取得情報出力:PDFドキュメント情報
*****************************************/
/* ファイルサイズの取得 */
long fileSize = docinfo.getContentSize();
resultBuffer.append("ファイルサイズ:" + fileSize + " Bytes<br>");
/* ページ数の取得 */
int pageNum = docinfo.getNumberOfPages();
resultBuffer.append("ページ数:" + pageNum + " Pages<br>");
/* ページサイズ(幅)の取得 */
double paperWidth = docinfo.getPaperWidth();
resultBuffer.append("ページ幅:" + paperWidth + " pts<br>");
/* ページサイズ(高さ)の取得 */
double paperHeight = docinfo.getPaperHeight();
resultBuffer.append("ページ高:" + paperHeight + " pts<br>");
/* 解像度取得 */
int resolution = docinfo.getResolution();
resultBuffer.append("解像度:" + resolution + " dpi<br>");
/* 階調取得 */
int gradation = docinfo.getGradation();
resultBuffer.append("階調:" + gradation + "<br>");
/* 最新のタイムスタンプ情報の取得 */
// PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp();
/* タイムスタンプリストの取得 */
PdfTimeStamp[] timeStampList = docinfo.getTimeStamps();
resultBuffer.append("タイムスタンプリスト:" + timeStampList.length + "<br>");
/* VRI付きタイムスタンプリストの取得 */
PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI();
if (vriTimeStampList != null) {
resultBuffer.append("VRI付きタイムスタンプリスト:" + vriTimeStampList.length + "<br>");
}
/* VRI付きでないタイムスタンプリストの取得 */
PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI();
if (notVriTimeStampList != null) {
resultBuffer.append("VRI付きでないタイムスタンプリスト:" + notVriTimeStampList.length + "<br>");
}
/*****************************************
* 取得情報出力:タイムスタンプ情報
*****************************************/
for (int i = 0; i < timeStampList.length; i++) {
resultBuffer.append("【TimeStamp[" + i + "]】<br>");
/* ハッシュアルゴリズムの取得 */
HASH_ALGORITHM hashAlgorithm = timeStampList[i]
.getHashAlgorithm();
resultBuffer.append(" ハッシュアルゴリズム:" + hashAlgorithm + "<br>");
/* 有効期限の取得 */
Date expirationDate = timeStampList[i]
.getTimeStampExpirationDate();
resultBuffer.append(" 有効期限:" + expirationDate + "<br>");
/* タイムスタンプ生成日時の取得 */
Date createDate = timeStampList[i].getCreationDate();
resultBuffer.append(" タイムスタンプ生成日時:" + createDate + "<br>");
/* 検証結果の取得 */
int validateResult = timeStampList[i].getValidateResult();
resultBuffer.append(" 検証結果:" + validateResult + "<br>");
/* 署名Vriが付加されているかの取得 */
boolean vriFlg = timeStampList[i].getVriFlg();
resultBuffer.append(" 署名VRIの付加:" + vriFlg + "<br>");
/* タイムスタンプ情報の取得 */
PdfTimeStampToken token = timeStampList[i].getTimeStampToken();
/*****************************************
* 取得情報出力:タイムスタンプトークン
*****************************************/
/* タイムスタンプデータ値の取得 */
byte[] tokenData = token.getData();
resultBuffer.append(" タイムスタンプデータ値:" + tokenData + "<br>");
/* 登録時のタイムスタンプハッシュ値の取得 */
byte[] registerDigest = token.getRegisterDigest();
resultBuffer.append(" 登録時のタイムスタンプハッシュ値:" + registerDigest + "<br>");
/* 検証時のタイムスタンプハッシュ値の取得 */
byte[] digest = token.getDigest();
resultBuffer.append(" 検証時のタイムスタンプハッシュ値:" + digest + "<br>");
}
} catch (PdfTimeStampException e) {
resultBuffer.append("文書タイムスタンプ付与:ERROR <br>");
resultBuffer.append("ステータス:" + e.getCode() + "<br>メッセージ:"+ e.getMessage() + "<br>");
}
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("延長タイムスタンプ付与:SUCCESS<br>");
/*****************************************
* 実行
*****************************************/
/* PDFおよびタイムスタンプ情報の取得 */
docinfo = service.getPdfDocument();
/*****************************************
* 取得情報出力:PDFドキュメント情報
*****************************************/
/* ファイルサイズの取得 */
long fileSize = docinfo.getContentSize();
resultBuffer.append("ファイルサイズ:" + fileSize + " Bytes<br>");
/* ページ数の取得 */
int pageNum = docinfo.getNumberOfPages();
resultBuffer.append("ページ数:" + pageNum + " Pages<br>");
/* ページサイズ(幅)の取得 */
double paperWidth = docinfo.getPaperWidth();
resultBuffer.append("ページ幅:" + paperWidth + " pts<br>");
/* ページサイズ(高さ)の取得 */
double paperHeight = docinfo.getPaperHeight();
resultBuffer.append("ページ高:" + paperHeight + " pts<br>");
/* 解像度取得 */
int resolution = docinfo.getResolution();
resultBuffer.append("解像度:" + resolution + " dpi<br>");
/* 階調取得 */
int gradation = docinfo.getGradation();
resultBuffer.append("階調:" + gradation + "<br>");
/* 最新のタイムスタンプ情報の取得 */
// PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp();
/* タイムスタンプリストの取得 */
PdfTimeStamp[] timeStampList = docinfo.getTimeStamps();
resultBuffer.append("タイムスタンプリスト:" + timeStampList.length + "<br>");
/* VRI付きタイムスタンプリストの取得 */
PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI();
if (vriTimeStampList != null) {
resultBuffer.append("VRI付きタイムスタンプリスト:" + vriTimeStampList.length + "<br>");
}
/* VRI付きでないタイムスタンプリストの取得 */
PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI();
if (notVriTimeStampList != null) {
resultBuffer.append("VRI付きでないタイムスタンプリスト:" + notVriTimeStampList.length + "<br>");
}
/*****************************************
* 取得情報出力:タイムスタンプ情報
*****************************************/
for (int i = 0; i < timeStampList.length; i++) {
resultBuffer.append("【TimeStamp[" + i + "]】<br>");
/* ハッシュアルゴリズムの取得 */
HASH_ALGORITHM hashAlgorithm = timeStampList[i]
.getHashAlgorithm();
resultBuffer.append(" ハッシュアルゴリズム:" + hashAlgorithm + "<br>");
/* 有効期限の取得 */
Date expirationDate = timeStampList[i]
.getTimeStampExpirationDate();
resultBuffer.append(" 有効期限:" + expirationDate + "<br>");
/* タイムスタンプ生成日時の取得 */
Date createDate = timeStampList[i].getCreationDate();
resultBuffer.append(" タイムスタンプ生成日時:" + createDate + "<br>");
/* 検証結果の取得 */
int validateResult = timeStampList[i].getValidateResult();
resultBuffer.append(" 検証結果:" + validateResult + "<br>");
/* 署名Vriが付加されているかの取得 */
boolean vriFlg = timeStampList[i].getVriFlg();
resultBuffer.append(" 署名VRIの付加:" + vriFlg + "<br>");
/* タイムスタンプ情報の取得 */
PdfTimeStampToken token = timeStampList[i].getTimeStampToken();
/*****************************************
* 取得情報出力:タイムスタンプトークン
*****************************************/
/* タイムスタンプデータ値の取得 */
byte[] tokenData = token.getData();
resultBuffer.append(" タイムスタンプデータ値:" + tokenData + "<br>");
/* 登録時のタイムスタンプハッシュ値の取得 */
byte[] registerDigest = token.getRegisterDigest();
resultBuffer.append(" 登録時のタイムスタンプハッシュ値:" + registerDigest + "<br>");
/* 検証時のタイムスタンプハッシュ値の取得 */
byte[] digest = token.getDigest();
resultBuffer.append(" 検証時のタイムスタンプハッシュ値:" + digest + "<br>");
}
} catch (PdfTimeStampException e) {
resultBuffer.append("延長タイムスタンプ付与:ERROR<br>");
resultBuffer.append("ステータス:" + e.getCode() + "<br>メッセージ:" + e.getMessage() + "<br>");
}
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("PDF文書のタイムスタンプ検証(validate):SUCCESS:[" + res + "]<br>");
} catch (PdfTimeStampException e) {
resultBuffer.append("PDF文書のタイムスタンプ検証(validate):ERROR<br>");
resultBuffer.append("ステータス:" + e.getCode() + "<br>メッセージ:" + e.getMessage() + "<br>");
}
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 + "]】<br>");
/* ハッシュアルゴリズムの取得 */
HASH_ALGORITHM hashAlgorithm = timeStampList[i]
.getHashAlgorithm();
resultBuffer.append(" ハッシュアルゴリズム:" + hashAlgorithm + "<br>");
/* 有効期限の取得 */
Date expirationDate = timeStampList[i]
.getTimeStampExpirationDate();
resultBuffer.append(" 有効期限:" + expirationDate + "<br>");
/* タイムスタンプ生成日時の取得 */
Date createDate = timeStampList[i].getCreationDate();
resultBuffer.append(" タイムスタンプ生成日時:" + createDate + "<br>");
/* 検証結果の取得 */
int validateResult = timeStampList[i].getValidateResult();
resultBuffer.append(" 検証結果:" + validateResult + "<br>");
/* 署名Vriが付加されているかの取得 */
boolean vriFlg = timeStampList[i].getVriFlg();
resultBuffer.append(" 署名VRIの付加:" + vriFlg + "<br>");
/* タイムスタンプ情報の取得 */
PdfTimeStampToken token = timeStampList[i].getTimeStampToken();
/*****************************************
* 取得情報出力:タイムスタンプトークン
*****************************************/
/* タイムスタンプデータ値の取得 */
byte[] tokenData = token.getData();
resultBuffer.append(" タイムスタンプデータ値:" + tokenData + "<br>");
/* 登録時のタイムスタンプハッシュ値の取得 */
byte[] registerDigest = token.getRegisterDigest();
resultBuffer.append(" 登録時のタイムスタンプハッシュ値:" + registerDigest + "<br>");
/* 検証時のタイムスタンプハッシュ値の取得 */
byte[] digest = token.getDigest();
resultBuffer.append(" 検証時のタイムスタンプハッシュ値:" + digest + "<br>");
}
} catch (PdfTimeStampException e) {
resultBuffer.append("PDF文書のタイムスタンプ検証(validateTs):ERROR<br>");
resultBuffer.append("ステータス:" + e.getCode() + "<br>メッセージ:" + e.getMessage() + "<br>");
}
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("ファイルサイズ:" + fileSize + " Bytes<br>");
/* ページ数の取得 */
int pageNum = docinfo.getNumberOfPages();
resultBuffer.append("ページ数:" + pageNum + " Pages<br>");
/* ページサイズ(幅)の取得 */
double paperWidth = docinfo.getPaperWidth();
resultBuffer.append("ページ幅:" + paperWidth + " pts<br>");
/* ページサイズ(高さ)の取得 */
double paperHeight = docinfo.getPaperHeight();
resultBuffer.append("ページ高:" + paperHeight + " pts<br>");
/* 解像度取得 */
int resolution = docinfo.getResolution();
resultBuffer.append("解像度:" + resolution + " dpi<br>");
/* 階調取得 */
int gradation = docinfo.getGradation();
resultBuffer.append("階調:" + gradation + "<br>");
/* 最新のタイムスタンプ情報の取得 */
//PdfTimeStamp timeStamp = docinfo.getLatestTimeStamp();
/* タイムスタンプリストの取得 */
PdfTimeStamp[] timeStampList = docinfo.getTimeStamps();
/* タイムスタンプが付与されていない場合は処理終了 */
if (timeStampList == null) {
resultBuffer.append("タイムスタンプが付与されていません。<br>");
resultBuffer.append("PDF文書の情報取得:SUCCESS<br>");
return resultBuffer.toString();
}
/* 付与されているタイムスタンプを出力 */
resultBuffer.append("タイムスタンプリスト:" + timeStampList.length + "<br>");
/* VRI付きタイムスタンプリストの取得 */
PdfTimeStamp[] vriTimeStampList = docinfo.getTimeStampsWithVRI();
if (vriTimeStampList != null) {
resultBuffer.append("VRI付きタイムスタンプリスト:" + vriTimeStampList.length + "<br>");
}
/* VRI付きでないタイムスタンプリストの取得 */
PdfTimeStamp[] notVriTimeStampList = docinfo.getTimeStampsWithNotVRI();
if (notVriTimeStampList != null) {
resultBuffer.append("VRI付きでないタイムスタンプリスト:" + notVriTimeStampList.length + "<br>");
}
/*****************************************
* 取得情報出力:タイムスタンプ情報
*****************************************/
for (int i = 0; i < timeStampList.length; i++) {
resultBuffer.append("【TimeStamp[" + i + "]】<br>");
/* ハッシュアルゴリズムの取得 */
HASH_ALGORITHM hashAlgorithm = timeStampList[i]
.getHashAlgorithm();
resultBuffer.append(" ハッシュアルゴリズム:" + hashAlgorithm + "<br>");
/* 有効期限の取得 */
Date expirationDate = timeStampList[i]
.getTimeStampExpirationDate();
resultBuffer.append(" 有効期限:" + expirationDate + "<br>");
/* タイムスタンプ生成日時の取得 */
Date createDate = timeStampList[i].getCreationDate();
resultBuffer.append(" タイムスタンプ生成日時:" + createDate + "<br>");
/* 検証結果の取得 */
int validateResult = timeStampList[i].getValidateResult();
resultBuffer.append(" 検証結果:" + validateResult + "<br>");
/* 署名Vriが付加されているかの取得 */
boolean vriFlg = timeStampList[i].getVriFlg();
resultBuffer.append(" 署名VRIの付加:" + vriFlg + "<br>");
/* タイムスタンプ情報の取得 */
PdfTimeStampToken token = timeStampList[i].getTimeStampToken();
/*****************************************
* 取得情報出力:タイムスタンプトークン
*****************************************/
/* タイムスタンプデータ値の取得 */
byte[] tokenData = token.getData();
resultBuffer.append(" タイムスタンプデータ値:" + tokenData + "<br>");
/* 登録時のタイムスタンプハッシュ値の取得 */
byte[] registerDigest = token.getRegisterDigest();
resultBuffer.append(" 登録時のタイムスタンプハッシュ値:" + registerDigest + "<br>");
/* 検証時のタイムスタンプハッシュ値の取得 */
byte[] digest = token.getDigest();
resultBuffer.append(" 検証時のタイムスタンプハッシュ値:" + digest + "<br>");
}
/*****************************************
* 実行結果出力
*****************************************/
resultBuffer.append("PDF文書の情報取得:SUCCESS<br>");
} catch (PdfTimeStampException e) {
resultBuffer.append("PDF文書の情報取得:ERROR<br>");
resultBuffer.append("ステータス:" + e.getCode() + "<br>メッセージ:" + e.getMessage() + "<br>");
}
finally{
}
return resultBuffer.toString();
}
%>
|
コラム
タイムスタンプ局のURL、ユーザID、および、パスワード情報は環境に合わせて指定してください。
注意
文字コードを UTF-8 にして保存してください。
プログラム実行¶
プログラム実行¶
メニューで『PdfTimeStampSample』を選択してください。作成したJSPファイルが実行されます。
JSPの実行エラー(コンパイルエラー)になってしまった場合には、エラーメッセージの内容に従いJSPプログラムを修正してください。
JSPプログラムが正しく動作しているにも関わらず実行時エラーになってしまう場合は、エラーの内容にしたがって環境を正しく溝築してください(環境を変更した場合は、サーバの再起動が必要になる場合があります)。