PKCS8私钥格式

1. Introduction

This document defines the syntax for private-key information and a Cryptographic Message Syntax (CMS) [RFC5652] content type for it.

2. Asymmetric Key Package CMS Content Type

The asymmetric key package CMS content type is used to transfer one or more plaintext asymmetric keys from one party to another.

generators SHOULD use DER [X.690] and receivers MUST support BER [X.690], which also includes DER [X.690].

ct-asymmetric-key-package CONTENT-TYPE ::=
{
    AsymmetricKeyPackage IDENTIFIED BY id-ct-KP-aKeyPackage 
}
id-ct-KP-aKeyPackage OBJECT IDENTIFIER ::=
{ 
    joint-iso-itu-t(2) 
    country(16) 
    us(840) 
    organization(1)
    gov(101) 
    dod(2) 
    infosec(1) 
    formats(2)
    key-package-content-types(78) 5
}
AsymmetricKeyPackage ::= SEQUENCE SIZE (1..MAX) OF OneAsymmetricKey

OneAsymmetricKey ::= SEQUENCE {
	version Version,
	--  If publicKey is present, then version is set to v2 else version is set to v1
    
    privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
    privateKey PrivateKey,
    attributes [0] Attributes OPTIONAL,
    ...,
    [
    	[2: publicKey [1] PublicKey OPTIONAL ]
    ],
    ...
}
PrivateKeyInfo ::= OneAsymmetricKey
-- PrivateKeyInfo is used by [P12]. If any items tagged as version
-- 2 are used, the version must be v2, else the version should be
-- v1. When v1, PrivateKeyInfo is the same as it was in [RFC5208].
Version ::= INTEGER { v1(0), v2(1) } (v1, ..., v2)
PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
{ 
    PUBLIC-KEY,
    { 
        PrivateKeyAlgorithms
    }
}
PrivateKey ::= OCTET STRING
-- Content varies based on type of key. The
-- algorithm identifier dictates the format of
-- the key.
-- For example
-- a DSA key is an INTEGER
-- an RSA key is represented as RSAPrivateKey as defined in [RFC3447]
-- an Elliptic Curve Cryptography (ECC) key is represented as ECPrivateKey as defined in [RFC5915]

PublicKey ::= BIT STRING
-- Content varies based on type of key. The
-- algorithm identifier dictates the format of
-- the key.
Attributes ::= SET OF Attribute { { OneAsymmetricKeyAttributes } }

3. Encrypted Private Key Info

EncryptedPrivateKeyInfo ::= SEQUENCE 
{
    encryptionAlgorithm EncryptionAlgorithmIdentifier,
    encryptedData EncryptedData 
}
EncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
{
    CONTENT-ENCRYPTION,
    {
        KeyEncryptionAlgorithms
    }
}
EncryptedData ::= OCTET STRING

4. Protecting the AsymmetricKeyPackage

CMS protecting content types, [RFC5652] and [RFC5083], can be used to provide security to the AsymmetricKeyPackage:

  • SignedData
  • EncryptedData
  • EnvelopedData
  • AuthenticatedData
  • AuthEnvelopedData

5. Other Private-Key Format Considerations

There are two other formats that have been used for the transport of asymmetric private keys.

OneAsymmetricKey and PrivateKeyInfo are the same structure; therefore, either can be saved as a .p8 file or copied in to the P12 KeyBag BAG-TYPE.

PEM

PEM,Privacy Enhanced Mail

.p8 files are sometimes PEM-encoded. When .p8 files are PEM encoded they use the .pem file extension. PEM encoding is either the Base64 encoding, from Section 4 of [RFC4648], of the DER-encoded EncryptedPrivateKeyInfo sandwiched between:

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

or the Base64 encoding, see Section 4 of [RFC4648], of the DER-encoded PrivateKeyInfo sandwiched between:

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

p12

Personal Information Exchange (PFX) Syntax Standard [P12], which is more commonly referred to as PKCS #12 or simply P12, is a transfer syntax for personal identity information, including private keys, certificates, miscellaneous secrets, and extensions.

The private key information, OneAsymmetricKey and PrivateKeyInfo, are carried in the P12 keyBag BAG-TYPE.

In current implementations, the file extensions .pfx and .p12 can be used interchangeably.

pvk

Microsoft’s private-key proprietary transfer syntax. The .pvk file extension is used for local storage.

参考资料

RFC 5208: Public-Key Cryptography Standards (PKCS) #8

RFC 5958: Asymmetric Key Packages (rfc-editor.org)

/docs/man3.0/man3/PEM_write_PrivateKey.html (openssl.org)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值