PsaExportPublicKey
Export a public key or the public part of a key pair in binary format. Opcode: 7 (0x0007
)
Parameters
Name | Type | Description |
---|---|---|
key_name | String | Name of the public key to export |
Results
Name | Type | Description |
---|---|---|
data | Vector of bytes | Buffer containing the key data |
Specific response status codes
PsaErrorInvalidArgument
: The key is neither a public key nor a key pair.
Description
The output of this function can be passed to PsaImportKey to create an object that is equivalent to the public key.
For standard key types, the output format is as follows:
- For RSA public keys, with key type
RsaPublicKey
, the DER encoding of the representation defined by Algorithms and Identifiers for the Internet X.509 Public Key Infrastructure Certifiate and Certificate Revocation List (CRL) Profile RFC 3279 §2.3.1 asRSAPublicKey
([1]
). - For elliptic curve public keys, with key type
EccPublicKey
, the format depends on the curve family:- For Weierstrass curve families sectXX, secpXX, FRP and Brainpool, the uncompressed
representation of an elliptic curve point as an octet string defined in SEC 1: Elliptic Curve
Cryptography SEC1 §2.3.3. If
m
is the bit size associated with the curve, i.e. the bit size ofq
for a curve overF_q
. The representation consists of:- The byte
0x04
; x_P
as aceiling(m/8)
-byte string, big-endian;y_P
as aceiling(m/8)
-byte string, big-endian.
- The byte
- For Montgomery curve family, the scalar value of the ‘public key’ in little-endian order as
defined by Elliptic Curves for Security RFC 7748
§6. This is a
ceiling(m/8)
-byte string wherem
is the key size in bits.- This is 32 bytes for Curve25519, computed as
X25519(private_key, 9)
. - This is 56 bytes for Curve448, computed as
X448(private_key, 5)
.
- This is 32 bytes for Curve25519, computed as
- For Weierstrass curve families sectXX, secpXX, FRP and Brainpool, the uncompressed
representation of an elliptic curve point as an octet string defined in SEC 1: Elliptic Curve
Cryptography SEC1 §2.3.3. If
- For Diffie-Hellman key exchange public keys, with key types
DhPublicKey, the format is the representation of the
public key
y = g^x mod p
as a big-endian byte string. The length of the byte string is the length of the base primep
in bytes.
Exporting a public key object or the public part of a key pair is always permitted, regardless of the key’s usage flags.
[1]
: The RSAPublicKey
representation is:
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e
}
Contract
Copyright 2019 Contributors to the Parsec project.