找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 940|回复: 6

[DCMTK] DCMTK简介九-dcmsign程序库

[复制链接]

293

主题

402

回帖

2565

积分

管理员

积分
2565

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2015-12-4 21:11:01 | 显示全部楼层 |阅读模式
本帖最后由 medimage 于 2015-12-4 21:28 编辑

九、dcmsign程序库
dcmsign是一个数字签名库和可用工具。这个模块包含了一些类,以创建DICOM数据集中的数字签名,并验证和删除签名。这个模块需要扩展的OpenSSL库的支持。

主要接口:
--DcmSignature: this class provides the main interface to the dcmsign module - it allows to create, examine and verify digital signatures in DICOM datasets or items. The methods in this class do not handle digital signatures embedded in sequence items within the dataset, other than providing helper functions that allow to locate and attach the sub-items separately. 在dcsignat.h中定义。
--SiSecurityProfile: 所有安全框架的抽象基类。abstract base class for all security profiles. 在sisprof.h文件中定义。
--SiCertificate: a class representing X.509 public key certificates. 在sicert.h文件中定义。

--SiPrivateKey: a class representing a private key. 在siprivat.h文件中定义。
--SiMAC: a base class for all classes that implement hash functions. 在simac.h文件中定义。

工具:
dcmsign: Sign and Verify DICOM Files

举例:
--验证一个DICOM文件中的所有签名。
DcmFileFormat fileformat;
if (fileformat.loadFile("test.dcm").good())
{
int counter = 0;          // counts the signatures in the DICOM file
int corrupt_counter = 0; // counts signatures that failed verification
DcmDataset *dataset = fileformat.getDataset();
DcmStack stack;           // stores current location within file
DcmSignature signer;      // signature handler
DcmItem *sigItem = DcmSignature::findFirstSignatureItem(*dataset, stack);
while (sigItem) // browse through items that contain digital signatures
{
    signer.attach(sigItem); // each item may contain multiple signatures
    for (unsigned long l=0; l < signer.numberOfSignatures(); ++l)
    {
      if (signer.selectSignature(l).good())
      {
        ++counter;
        if (signer.verifyCurrent().bad()) // verify signature
           corrupt_counter++;
      }
    }
    signer.detach();
    sigItem = DcmSignature::findNextSignatureItem(*dataset, stack);
}
if (counter == 0)
      cerr << "no signatures found in dataset." << endl;
else
      cerr << counter << " signatures verified in dataset, "
           << corrupt_counter << " corrupted." << endl;
}
--给一个DICOM文件增加签名。

DcmFileFormat fileformat;
if (fileformat.loadFile("test.dcm").good())
{
DcmDataset *dataset = fileformat.getDataset();
SiCreatorProfile profile; // select the "RSA Creator Profile"
SiRIPEMD160 mac;           // use RIPEMD160 as MAC algorithm
DcmSignature signer;       // signature handler
SiCertificate cert;        // our certificate
if (cert.loadCertificate("certificate.pem", X509_FILETYPE_PEM).bad())
{
    cerr << "unable to load certificate" << endl;
    return;
}
SiPrivateKey key; // private key, must be unencrypted here
if (key.loadPrivateKey("privkey.pem", X509_FILETYPE_PEM).bad())
{
    cerr << "unable to load private key" << endl;
    return;
}
signer.attach(dataset); // connect handler to data set
if (signer.createSignature(key, cert, mac, profile).good())
{
    fileformat.saveFile("test_signed.dcm"); // write back
}
}



回复

使用道具 举报

13

主题

393

回帖

1041

积分

版主

积分
1041

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-13 19:52:52 | 显示全部楼层
一直在寻找这个,多谢了
回复

使用道具 举报

62

主题

415

回帖

1349

积分

等待验证会员

积分
1349

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-19 15:03:47 | 显示全部楼层
谢谢LZ
回复

使用道具 举报

4

主题

408

回帖

1070

积分

版主

积分
1070

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-20 10:39:19 | 显示全部楼层
dddddddddddddddddddddddddddd
回复

使用道具 举报

0

主题

391

回帖

781

积分

高级会员

积分
781

最佳新人

发表于 2016-5-22 14:41:11 | 显示全部楼层
顶贴
回复

使用道具 举报

21

主题

418

回帖

1123

积分

版主

积分
1123

热心会员推广达人优秀版主荣誉管理论坛元老

发表于 2016-5-24 05:53:10 | 显示全部楼层
LZ高人啊,我来学习了
回复

使用道具 举报

1

主题

400

回帖

819

积分

高级会员

积分
819

最佳新人

发表于 2016-5-24 17:03:19 | 显示全部楼层
厉害
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|关于我们|医维基|网站地图|Archiver|手机版|医疗之家 ( 沪ICP备2023001278号-1 )

GMT+8, 2025-6-3 11:25 , Processed in 0.439195 second(s), 27 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表