当前位置: 首页 > news >正文

java pkcs7 pem_RSA私钥和公钥文件格式 (pkcs#7, pkcs#8, pkcs#12, pem)

[输入证书: cert/test.pfx 密码假设为123456 输出证书:cert/test.jks 在cmd下运行: D:\temp\certtest>java  ConvertPKCS12ToJKS 显示 keystore type=PKCS12 alias=[my ce

Format Name Description PKCS #7 Cryptographic Message Syntax Standard A PKCS #7 file can be used to store certificates, which is a SignedData structure without data (just the certificates). The file name extension is usually

.p7b,

.p7c PKCS #8 Private-Key Information Syntax Standard. Used to carry private certificate keypairs (encrypted or unencrypted). PKCS #12 Personal Information Exchange Syntax Standard. Defines a file format commonly used to store private keys with accompanying public key certificates, protected with a password-based symmetric key. It is the successor to PFX from Microsoft. DER Distinguished Encoding Rules A binary format for keys or certificates. It is a message transfer syntax specified by the ITU in X.690. PEM Privacy Enhanced Mail Base64 encoded DER certificates or keys, with additional header and footer lines.

The PEM private key format uses the header and footer lines:

-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----

The PEM public key format uses the header and footer lines:

-----BEGIN PUBLIC KEY-----

-----END PUBLIC KEY-----

The PEM certificate uses the header and footer lines:

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

RSA Public Key file (PKCS#1)

The RSA Public key PEM file is specific for RSA keys.

It starts and ends with the tags:

-----BEGIN RSA PUBLIC KEY-----

BASE64 ENCODED DATA

-----END RSA PUBLIC KEY-----

Within the base64 encoded data the following DER structure is present:

RSAPublicKey ::= SEQUENCE {

modulus INTEGER, -- n

publicExponent INTEGER -- e

}

Public Key file (PKCS#8)

Because RSA is not used exclusively inside X509 and SSL/TLS, a more generic key format is available in the form of PKCS#8, that identifies the type of public key and contains the relevant data.

It starts and ends with the tags:

-----BEGIN PUBLIC KEY-----

BASE64 ENCODED DATA

-----END PUBLIC KEY-----

Within the base64 encoded data the following DER structure is present:

PublicKeyInfo ::= SEQUENCE {

algorithm AlgorithmIdentifier,

PublicKey BIT STRING

}

AlgorithmIdentifier ::= SEQUENCE {

algorithm OBJECT IDENTIFIER,

parameters ANY DEFINED BY algorithm OPTIONAL

}

So for an RSA public key, the OID is 1.2.840.113549.1.1.1 and there is a RSAPublicKey as the PublicKey key data bitstring.

RSA Private Key file (PKCS#1)

The RSA private key PEM file is specific for RSA keys.

It starts and ends with the tags:

-----BEGIN RSA PRIVATE KEY-----

BASE64 ENCODED DATA

-----END RSA PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

RSAPrivateKey ::= SEQUENCE {

version Version,

modulus INTEGER, -- n

publicExponent INTEGER, -- e

privateExponent INTEGER, -- d

prime1 INTEGER, -- p

prime2 INTEGER, -- q

exponent1 INTEGER, -- d mod (p-1)

exponent2 INTEGER, -- d mod (q-1)

coefficient INTEGER, -- (inverse of q) mod p

otherPrimeInfos OtherPrimeInfos OPTIONAL

}

Private Key file (PKCS#8)

Because RSA is not used exclusively inside X509 and SSL/TLS, a more generic key format is available in the form of PKCS#8, that identifies the type of private key and contains the relevant data.[ private static final String KEY_ALGORITHM = "RSA"; private static final String PUBLIC_KEY ="publicKey"; private static final String PRIVATE_KEY ="priv

The unencrypted PKCS#8 encoded data starts and ends with the tags:

-----BEGIN PRIVATE KEY-----

BASE64 ENCODED DATA

-----END PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

PrivateKeyInfo ::= SEQUENCE {

version Version,

algorithm AlgorithmIdentifier,

PrivateKey BIT STRING

}

AlgorithmIdentifier ::= SEQUENCE {

algorithm OBJECT IDENTIFIER,

parameters ANY DEFINED BY algorithm OPTIONAL

}

So for an RSA private key, the OID is 1.2.840.113549.1.1.1 and there is a RSAPrivateKey as the PrivateKey key data bitstring.

The encrypted PKCS#8 encoded data start and ends with the tags:

-----BEGIN ENCRYPTED PRIVATE KEY-----

BASE64 ENCODED DATA

-----END ENCRYPTED PRIVATE KEY-----

Within the base64 encoded data the following DER structure is present:

EncryptedPrivateKeyInfo ::= SEQUENCE {

encryptionAlgorithm EncryptionAlgorithmIdentifier,

encryptedData EncryptedData

}

EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier

EncryptedData ::= OCTET STRING

The EncryptedData OCTET STRING is a PKCS#8 PrivateKeyInfo (see above).

https://polarssl.org/kb/cryptography/asn1-key-structures-in-der-and-pem[利用OpenSSL的PKCS12_parse函数进行证书格式转换的参考代码。 目前这个函数还存在内存泄漏,这是OpenSSL 的Bug,做法上完全可以参考。EVP_CIPHER *g_pEncAlg = NULL;ESMTR

相关文章:

  • java long integer_java Long、Integer 、Double、Boolean类型 不能直接比较
  • java response 调用js_java httpclient 请求的response为text/javascript,如何处理响应的js对象?...
  • java doublebuffer_Java中的DoubleBufferallocate()方法
  • 银联数据服务中心java工程师面试_中国银联JAVA开发工程师面试经验|面试题 - 职朋职业圈...
  • java调用datastage_Datastage重启服务
  • mysql中mapping标签的作用_MyBatis全局配置文件标签详解
  • python编写字典库_Python绘图Turtle库详解
  • go解析mysql binlog_一个应用它提取MySQL binlog,解析binlog并将增量更新数据推送到不同的接收器...
  • java运行时读取注解_Java自定义注解和运行时靠反射获取注解
  • java long polling_如何在Spring Boot应用程序中实现Long Polling REST endpoints ?
  • java获取其他线程的错误_java多线程开发容易犯的错误
  • java 检索数据_java代码实现搜索elasticsearch索引数据
  • java非异步线程池_Spring Boot利用@Async异步调用:ThreadPoolTaskScheduler线程池的优雅关闭详解...
  • mongo java driver 3.2_MongoDB-JAVA-Driver 3.2版本常用代碼全整理(2) - 查詢
  • java中标记怎么用_在Java中使用标记(标签)
  • [微信小程序] 使用ES6特性Class后出现编译异常
  • [译] React v16.8: 含有Hooks的版本
  • 【许晓笛】 EOS 智能合约案例解析(3)
  • Angularjs之国际化
  • java8-模拟hadoop
  • log4j2输出到kafka
  • Median of Two Sorted Arrays
  • PHP 7 修改了什么呢 -- 2
  • Rancher如何对接Ceph-RBD块存储
  • Tornado学习笔记(1)
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • 给新手的新浪微博 SDK 集成教程【一】
  • 缓存与缓冲
  • 机器学习学习笔记一
  • 基于OpenResty的Lua Web框架lor0.0.2预览版发布
  • 七牛云 DV OV EV SSL 证书上线,限时折扣低至 6.75 折!
  • 前端性能优化——回流与重绘
  • 如何将自己的网站分享到QQ空间,微信,微博等等
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 一天一个设计模式之JS实现——适配器模式
  • ​iOS安全加固方法及实现
  • ​虚拟化系列介绍(十)
  • #NOIP 2014# day.1 T3 飞扬的小鸟 bird
  • $redis-setphp_redis Set命令,php操作Redis Set函数介绍
  • (C语言)逆序输出字符串
  • (剑指Offer)面试题41:和为s的连续正数序列
  • (南京观海微电子)——I3C协议介绍
  • (三)Honghu Cloud云架构一定时调度平台
  • (十)DDRC架构组成、效率Efficiency及功能实现
  • (四)TensorRT | 基于 GPU 端的 Python 推理
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • **PyTorch月学习计划 - 第一周;第6-7天: 自动梯度(Autograd)**
  • ... fatal error LINK1120:1个无法解析的外部命令 的解决办法
  • .Net 中Partitioner static与dynamic的性能对比
  • .net6使用Sejil可视化日志
  • .NET开源快速、强大、免费的电子表格组件
  • .NET企业级应用架构设计系列之结尾篇
  • .NET与 java通用的3DES加密解密方法
  • ::before和::after 常见的用法
  • ?.的用法