CMS/PKCS#7 读书笔记

来源:互联网 发布:淘宝取消已付款的订单 编辑:程序博客网 时间:2024/06/07 01:05

只写干货,不搞花活。

CMS和PKCS

CMS,全称Cryptographic Message Syntax,原始定义来自于RFC5652。
PKCS,全称Public Key Cryptography Standards,由一堆RFC文档组成:

PKCS 名称 RFC #1 RSA Cryptography Standard 3447 #2 已撤销 N/A #3 Diffie–Hellman Key Agreement Standard None #4 已撤销 N/A #5 Password-based Encryption Standard 2898 #6 Extended-Certificate Syntax Standard None #7 Cryptographic Message Syntax Standard 2315 & 5652 #8 Private-Key Information Syntax Standard 5958 #9 Selected Attribute Types 2985 #10 Certification Request Standard 2986 #11 Cryptographic Token Interface None #12 Personal Information Exchange Syntax Standard 7292 #13 Elliptic Curve Cryptography Standard None #14 Pseudo-random Number Generation None #15 Cryptographic Token Information Format Standard None

PKCS #7

这东西是一个安全服务,独立于实现和具体的加密算法。主要包括两部分内容:

  • 数据加密(Data Encryption)
    • 用数字信封(Digital Envelopes)来实现
  • 身份验证和数据完整性验证(Entity Authentication & Data Integrity)
    • 用数字签名(Digital Signatures)来实现,支持多用户同时签名。

以上两部分内容可以包括一些额外的属性,这些属性可以是未加密的。

数字信封(Digital Envelopes)

实现流程:

  • 发送方
    • 生成session_key
    • 用session_key对数据进行加密
    • 用接收方公钥对session_key进行加密
    • 信封 = 加密后的数据 + 加密后的session_key
  • 接收方
    • 解密session_key
    • 用session_key解密数据

实际例子:S/MIME邮件
如何生成session_key,有两个方法:

  • Key Transport算法:一般就是RSA算法
  • Key Agreement算法:Diffie-Hellman 密钥一致性算法(PKCS#3),也是基于大数分解。具体算法在参考文献中。

身份验证和数据完整性验证(Entity Authentication & Data Integrity)

三个基本概念:

  • Integrity:数据没有被“动”过,“动”包括修改、删除、冗余等等
  • Authentication:指的是这个数据“有很大可能性”是来自于它声称自己来自的地方
  • Authenticity:副署签名,类似现实生活中“公证服务”的东西。PKCS#7只支持一级“公证”。

实际例子:S/MIME邮件
此处仍然是允许多方对一组数据进行签名的。
对于一个数据的签名,可以有以下两种情况:

  • Nondetached:数据和签名在一起
  • Detached:只有签名,没有数据。此处比较常用。

参考文献

  • MSDN:
    • https://msdn.microsoft.com/en-us/library/ms180946(v=vs.85).aspx
    • https://msdn.microsoft.com/en-us/library/ms180951(v=vs.85).aspx
    • https://msdn.microsoft.com/en-us/library/ms180950(v=vs.85).aspx
  • Wikipedia:
    • https://en.wikipedia.org/wiki/PKCS
    • https://en.wikipedia.org/wiki/Cryptographic_Message_Syntax
  • StackExchange:
    • http://security.stackexchange.com/questions/93322/difference-between-authentication-integrity-and-data-origin-authentication
    • http://crypto.stackexchange.com/questions/5458/should-we-sign-then-encrypt-or-encrypt-then-sign
  • Key Transport:
    • https://lists.w3.org/Archives/Public/public-xmlsec/2009May/att-0032/Key_Encapsulation.pdf
    • http://www.di-mgt.com.au/rsa_alg.html
  • Key Agreement:
    • https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange
    • http://www.di-mgt.com.au/public-key-crypto-discrete-logs-0.html
    • https://www.cs.umd.edu/~clancy/ents689i/689iwk3.pdf
  • Sample Code (C#)
    • https://msdn.microsoft.com/en-us/library/ms180955(v=vs.85).aspx
    • https://msdn.microsoft.com/en-us/library/ms180955(v=vs.85).aspx
  • Others:
    • http://world.std.com/~dtd/sign_encrypt/sign_encrypt7.html
    • http://paulstovell.com/blog/x509certificate2
0 0
原创粉丝点击