PKCS#1: RSA加密时摘要值规范

RSA的加密和签名标准是类似的,加密时的摘要值结构如下

即非普通的hash摘要值,而是der编码结构的hash摘要值,用ASN1工具打开

 可以快速的组装成一个der编码结构的摘要值,代码如下


ByteArrayOutputStream digestInfoValueBuf = new ByteArrayOutputStream();
digestInfoValueBuf.write(signatureConfig.getHashMagic());
digestInfoValueBuf.write(hashData);
hashData = digestInfoValueBuf.toByteArray();

hashData为摘要值,signatureConfig.getHashMagic()为获取的密钥算法标识符字节值

	switch (getDigestAlgo()) {
		case sha1:
			result = new byte[] { 0x30, 0x1f, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14 };
			break;
		case sha224:
			result = new byte[] { 0x30, 0x2b, 0x30, 0x0b, 0x06, 0x09, 0x60, (byte) 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x04, 0x1c };
			break;
		case sha256:
			result = new byte[] { 0x30, 0x2f, 0x30, 0x0b, 0x06, 0x09, 0x60, (byte) 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x04, 0x20 };
			break;
		case sha384:
			result = new byte[] { 0x30, 0x3f, 0x30, 0x0b, 0x06, 0x09, 0x60, (byte) 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x04, 0x30 };
			break;
		case sha512:
			result = new byte[] { 0x30, 0x4f, 0x30, 0x0b, 0x06, 0x09, 0x60, (byte) 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x04, 0x40 };
			break;
		case ripemd128:
			result = new byte[] { 0x30, 0x1b, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x02, 0x04, 0x10 };
			break;
		case ripemd160:
			result = new byte[] { 0x30, 0x1f, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x24, 0x03, 0x02, 0x01, 0x04, 0x14 };
			break;

0x30代表一个SEQUENCE,sha1对应的密钥算法标识为13字节,摘要值为20字节 ,拼接起来就是一个可以用ASN1工具打开的der编码结构的摘要值

RSA公司的PKCS(Public Key Cryptography Standards)系列标准。 官方网站的相关页面和链接好像已经失效。经过精心查找和整理,这可能是目前能收集到的最全的版本,包括如下版本: PKCS #1 v2.2: RSA Cryptography Standard PKCS #1 v2.1: RSA Cryptography Standard PKCS #1 v2.0: RSA Cryptography Standard PKCS #1 v2.0 Amendment 1: Multi-Prime RSA PKCS #1: RSA Encryption Standard PKCS #3: Diffie-Hellman Key-Agreement Standard PKCS #5 v2.1: Password-Based Cryptography Standard PKCS #5 v2.0: Password-Based Cryptography Standard PKCS #5: Password-Based Encryption Standard PKCS #6: Extended-Certificate Syntax Standard PKCS #7: Cryptographic Message Syntax Standard PKCS #8: Private-Key Information Syntax Standard PKCS #9 v2.0: Selected Object Classes and Attribute Types PKCS #9 v2.0 Amendment 1 PKCS #9: Selected Attribute Types PKCS #10 v1.7: Certification Request Syntax Standard PKCS #10: Certification Request Syntax Standard PKCS #11 v2.20: Cryptographic Token Interface Standard PKCS #11 v2.11: Cryptographic Token Interface Standard PKCS #11 Profiles For Mobile Devices PKCS #11 v2.10: Cryptographic Token Interface Standard PKCS #11: Cryptographic Token Interface Standard PKCS #11: Cryptographic Token Interface Standard PKCS #11: Cryptographic Token Interface Standard PKCS #12 v1.1: Personal Information Exchange Syntax PKCS 12 v1.0: Personal Information Exchange Syntax PKCS #12 v1.0 Technical Corrigendum 1 PKCS #15: Conformance Profile Specification PKCS #15 v1.1 Technical Corrigendum 1 PKCS #15 v1.1 Technical Corrigendum 2 PKCS #15 v1.0: Cryptographic Token Information Format Standard PKCS #15 v1.0 Amendment 1 PKCS #15 v1.1: Cryptographic Token Information Syntax Standard
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值