Supported Elliptic Curve (EC) Key Formats
All keys are the same key (nistp256 / secp256r1) encoded differently. Encrypted keys use demo
as the key.
See EC: Supported Formats for a more in depth discussion of the various formats (the features they support, the standards to which they conform, etc).
PKCS1
Private Keys
Named Curve
Generated with $key->toString('PKCS1')
.
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIEqT+eRC3V7MI/SUWQD0cLU30uAjUaqSiLPtvKzR4jwKoAoGCCqGSM49
AwEHoUQDQgAErPJyxEu2/oKCrJaaTVTrq39DKJ2XcN6W+k8UvGf+Y/lDWNbFitQo
cabsDUvSN0edHH3UKP5QPTz4cOlyIPMrXQ==
-----END EC PRIVATE KEY-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS1::useSpecifiedCurve()
and then $key->toString('PKCS1')
.
-----BEGIN EC PRIVATE KEY-----
MIIBTgIBAQQgSpP55ELdXswj9JRZAPRwtTfS4CNRqpKIs+28rNHiPAqggeAwgd0C
AQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAAAAAAAAAAAAAA////////////////
MEQEIP////8AAAABAAAAAAAAAAAAAAAA///////////////8BCBaxjXYqjqT57Pr
vVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwRBBGsX0fLhLEJH+Lzm5WOkQPJ3A32BLesz
oPShOUXYmMKWT+NC4v4af5uO5+tKfA+eFivOM1drMV7Oy7ZAaDe/UfUCIQD/////
AAAAAP//////////vOb6racXnoTzucrC/GMlUaFEA0IABKzycsRLtv6CgqyWmk1U
66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08+HDpciDz
K10=
-----END EC PRIVATE KEY-----
Encrypted Private Keys
Named Curve
Generated with $key->withPassword('demo')->toString('PKCS1')
.
-----BEGIN EC PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,0D74A1F3DB0F51121E9DA1B28A0AB2BD
NZfHlU+Ln86s5DlbTdTb/P6JXAAOEsONC3ruujq2ZEU7v47I578aQGmjV6lOvyYN
y4GMK+Mn8tAuap2TZYk09Ucr32fFG3H8CaXILjYHivorUuRhOk8g/l1JHnf7M0YH
uuOcI+Fk3RN2CPktcdHp59OtgZwny2IySqNiw/F/5Y4=
-----END EC PRIVATE KEY-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS1::useSpecifiedCurve()
and then $key->withPassword('demo')->toString('PKCS1')
.
-----BEGIN EC PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,952C100E8CC7DC068297848512B6598F
cgkqw+xfC5RUAyiU9tlt3du6HH+c+RZYaLSGUcfRlmSoW9ohMr8dadCs66npqXtf
kbgEotqL8IwaIA2q9qGpsCa19mvRS0Ys5JyQEmopHGIrm571NYiXWT06iwxHTyJb
XRR70iPVluG7wPK+C8BhEXWzE6GU5yIbe46GFxLE/SipDyjvs2HAZCM8PHsqoJa6
fx11e45kcL+FGdLQbjzP9DZF0K1825A/yWB6jyLgdhMrghFFRd47G+UDdJ+Ph58l
EM8Q1VL/azCgSvh15ACQ7e4SCk3XCqG5mWJRVO0+JTR14hFlH7cZKtXZ/dZOtZgz
8MvutZikiTDWWgG/Zt+czt2lEPy8B7BLNsR1qhcD8k8QdNLPHcCa+5eD4WsHy/W2
u2DZ/2vUGB1v2SOnbNboRut6PQE+by3d3xdTVFugZ1ABRNBUR/CdGxMRp82USiC3
OmX98QrbsaxIO5K6Um+/YA==
-----END EC PRIVATE KEY-----
Parameters
Named Curve
Generated with $key->getParameters()->toString('PKCS1')
.
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS1::useSpecifiedCurve()
and then $key->getParameters()->toString('PKCS1')
.
-----BEGIN EC PARAMETERS-----
MIHdAgEBMCwGByqGSM49AQECIQD/////AAAAAQAAAAAAAAAAAAAAAP//////////
/////zBEBCD/////AAAAAQAAAAAAAAAAAAAAAP///////////////AQgWsY12Ko6
k+ez671VdpiGvGUdBrDMU7D2O848PifSYEsEQQRrF9Hy4SxCR/i85uVjpEDydwN9
gS3rM6D0oTlF2JjClk/jQuL+Gn+bjufrSnwPnhYrzjNXazFezsu2QGg3v1H1AiEA
/////wAAAAD//////////7zm+q2nF56E87nKwvxjJVE=
-----END EC PARAMETERS-----
PKCS8
Private Keys
Named Curve
Generated with $key->toString('PKCS8')
.
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgSpP55ELdXswj9JRZ
APRwtTfS4CNRqpKIs+28rNHiPAqhRANCAASs8nLES7b+goKslppNVOurf0MonZdw
3pb6TxS8Z/5j+UNY1sWK1ChxpuwNS9I3R50cfdQo/lA9PPhw6XIg8ytd
-----END PRIVATE KEY-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS8::useSpecifiedCurve()
and then $key->toString('PKCS8')
.
-----BEGIN PRIVATE KEY-----
MIIBXgIBADCB6QYHKoZIzj0CATCB3QIBATAsBgcqhkjOPQEBAiEA/////wAAAAEA
AAAAAAAAAAAAAAD///////////////8wRAQg/////wAAAAEAAAAAAAAAAAAAAAD/
//////////////wEIFrGNdiqOpPns+u9VXaYhrxlHQawzFOw9jvOPD4n0mBLBEEE
axfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5RdiYwpZP40Li/hp/m47n60p8D54W
K84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA//////////+85vqtpxeehPO5ysL8
YyVRBG0wawIBAQQgSpP55ELdXswj9JRZAPRwtTfS4CNRqpKIs+28rNHiPAqhRANC
AASs8nLES7b+goKslppNVOurf0MonZdw3pb6TxS8Z/5j+UNY1sWK1ChxpuwNS9I3
R50cfdQo/lA9PPhw6XIg8ytd
-----END PRIVATE KEY-----
Encrypted Private Keys
Named Curve
Generated with $key->withPassword('demo')->toString('PKCS8')
.
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIHsMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAgSAksBQ9sCqQICCAAw
DAYIKoZIhvcNAgkFADAdBglghkgBZQMEAQIEEBVJUSnfBOUCx7FnWtt+pzoEgZCQ
f5gKEy9lnPcM7SgrNBOXNk9mPHSTO1D4UIlPdPtxbPPYM2ULWrxrQoQ0iSmXUp1n
0jHfDbnBlgDTS/8ezcnaRDuusZojGNUZg1DfJ3fDxKl6v/zxj1aqNtoyco7uDWuc
YQEdJEzPsVKYMa37gdGp5+2nv/Of/sVss+t8+6IHs445JC15ZF5XirVqx5qUjxQ=
-----END ENCRYPTED PRIVATE KEY-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS8::useSpecifiedCurve()
and then $key->withPassword('demo')->toString('PKCS8')
.
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIBzTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQIvXl/jJoRTfICAggA
MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAECBBCOWt/n7mCGfhpheWWfezOfBIIB
cGmNkXw1hYneO8XKQvKHSauJ8aUWrh9fc+nTNXq171vJtdZpQN/NcJ5TYA4yEKa1
mquL8Jeoauy9HGXo2g1nE6vkRlyTPIzAGXhdzNUfeFjl4DpClELkfzgLDoSUKP7R
4pziC0fqxmZDTJVaNludMrB3JV8ET+abg9MRAr/XqxflTq+kvLl/nvO6UBuEVbPB
0/l79vZAIJFFBB3L6DcVB8yesGHbbJCeIqG3AoxRgUIK7JBCDWpO+e19L13q9NpZ
MBB+dPfx9T3PYFPQ1YBjHDlVKuPDImL3F6pLQglyBj4ImoT2VAOABiSKamos4jxW
u21rdiy8soQrgUpnY1uUngE29hggSz5kfP5jQW59i/dkXPkRte4v9z38ijsQs1uA
6jAqk/SHUCdgWbOTFhXt7xjKLCpO26GrQ7a+mQcBjkVa8aZQwdVVpatIGfEdQfnl
xje33obeN/yjl+x/eFAfd+fUDN907fRZO8Sko956uQRy
-----END ENCRYPTED PRIVATE KEY-----
Public Keys
Named Curve
Generated with $key->getPublicKey()->toString('PKCS8')
.
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAErPJyxEu2/oKCrJaaTVTrq39DKJ2X
cN6W+k8UvGf+Y/lDWNbFitQocabsDUvSN0edHH3UKP5QPTz4cOlyIPMrXQ==
-----END PUBLIC KEY-----
Specified Curve
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\PKCS8::useSpecifiedCurve()
and then $key->getPublicKey()->toString('PKCS8')
.
-----BEGIN PUBLIC KEY-----
MIIBMDCB6QYHKoZIzj0CATCB3QIBATAsBgcqhkjOPQEBAiEA/////wAAAAEAAAAA
AAAAAAAAAAD///////////////8wRAQg/////wAAAAEAAAAAAAAAAAAAAAD/////
//////////wEIFrGNdiqOpPns+u9VXaYhrxlHQawzFOw9jvOPD4n0mBLBEEEaxfR
8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5RdiYwpZP40Li/hp/m47n60p8D54WK84z
V2sxXs7LtkBoN79R9QIhAP////8AAAAA//////////+85vqtpxeehPO5ysL8YyVR
A0IABKzycsRLtv6CgqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L
0jdHnRx91Cj+UD08+HDpciDzK10=
-----END PUBLIC KEY-----
PuTTY
Private Keys (v2)
Generated with $key->toString('PuTTY')
.
PuTTY-User-Key-File-2: ecdsa-sha2-nistp256
Encryption: none
Comment: phpseclib-generated-key
Public-Lines: 3
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6C
gqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08
+HDpciDzK10=
Private-Lines: 1
AAAAIQBKk/nkQt1ezCP0lFkA9HC1N9LgI1Gqkoiz7bys0eI8Cg==
Private-MAC: 9239cacc5e71079d25f63d03941c5a35b5304f6c
Encrypted Private Keys (v2)
Generated with $key->withPassword('demo')->toString('PuTTY')
.
PuTTY-User-Key-File-2: ecdsa-sha2-nistp256
Encryption: aes256-cbc
Comment: phpseclib-generated-key
Public-Lines: 3
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6C
gqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08
+HDpciDzK10=
Private-Lines: 1
U43Vy/gRjjfRA8Nbsy4Mremrnz3n49fTCwDdB2t1Nr9di16WaoBb582T489sn5ff
Private-MAC: 1a89ef91b9a3fcc4d3ad9033a06bf5cbd36395d9
Private Keys (v3)
Generated with $key->toString('PuTTY', ['version' => 3])
.
PuTTY-User-Key-File-3: ecdsa-sha2-nistp256
Encryption: none
Comment: phpseclib-generated-key
Public-Lines: 3
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6C
gqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08
+HDpciDzK10=
Private-Lines: 1
AAAAIEqT+eRC3V7MI/SUWQD0cLU30uAjUaqSiLPtvKzR4jwK
Private-MAC: 434b8765b1cca200a07daf361e7f1cbc6f7b801c0acc5bac0ad81d57144d179a
Encrypted Private Keys (v3)
Generated with $key->withPassword('demo')->toString('PuTTY', ['version' => 3])
.
PuTTY-User-Key-File-3: ecdsa-sha2-nistp256
Encryption: aes256-cbc
Comment: phpseclib-generated-key
Public-Lines: 3
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6C
gqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08
+HDpciDzK10=
Key-Derivation: Argon2id
Argon2-Memory: 8192
Argon2-Passes: 13
Argon2-Parallelism: 1
Argon2-Salt: a682b1d606e5e3baab0ef26e754f1c68
Private-Lines: 1
Vv79j4MLaDOCn/UPKDKiAyuMpyxhHwcnN136PKJbUqGhSByQoTYRbNtmzPK3DDVd
Private-MAC: 626ddc4a6d6a14aa2bfdc16c591e9d12c05f2b4ddf8cde9c973a38fd0ef0618e
Public Keys
Generated with $key->getPublicKey()->toString('PuTTY')
.
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "phpseclib-generated-key"
AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6C
gqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08
+HDpciDzK10=
---- END SSH2 PUBLIC KEY ----
OpenSSH
Private Keys
Generated with $key->toString('OpenSSH')
.
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS
1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQSs8nLES7b+goKslppNVOurf0MonZdw
3pb6TxS8Z/5j+UNY1sWK1ChxpuwNS9I3R50cfdQo/lA9PPhw6XIg8ytdAAAAsJreM3qa3j
N6AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6CgqyW
mk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08+HDpciDzK1
0AAAAgSpP55ELdXswj9JRZAPRwtTfS4CNRqpKIs+28rNHiPAoAAAAXcGhwc2VjbGliLWdl
bmVyYXRlZC1rZXkB
-----END OPENSSH PRIVATE KEY-----
Encrypted Private Keys
Generated with $key->withPassword('demo')->toString('OpenSSH')
.
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAadYAW13
jKwd2h4/sgh9dvAAAAEAAAAAEAAABoAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlz
dHAyNTYAAABBBKzycsRLtv6CgqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A
1L0jdHnRx91Cj+UD08+HDpciDzK10AAACwkOE6duVEIZ9scCkgw3Q/SFIgyaU9f2K0UChk
DZRCuS5jzwpw5cTvCuCBGocd9QtdZJPoiVxphzXdOfoaeKeWBE5rcLr7CYQyxhOyoZbJHP
mBAQ0SmtdXOFvgr9SrgU04Czovt6/d50oDImbKvwtiH/QetzkIRDiSpUwpXLF118H67vXH
NqH410tqKJYGAlKDZZV9HO68cQpUId4VlCn60Qt2Q0Ug3o0uBkg2M4erWks=
-----END OPENSSH PRIVATE KEY-----
Public Keys
Generated with $key->getPublicKey()->toString('OpenSSH')
.
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKzycsRLtv6CgqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08+HDpciDzK10= phpseclib-generated-key
JWK
Note that the actual keys generated are not "beautified" as these examples are.
Private Keys
Generated with $key->toString('JWK')
.
{
"keys": [
{
"kty": "EC",
"crv": "P-256",
"x": "rPJyxEu2_oKCrJaaTVTrq39DKJ2XcN6W-k8UvGf-Y_k=",
"y": "Q1jWxYrUKHGm7A1L0jdHnRx91Cj-UD08-HDpciDzK10=",
"d": "SpP55ELdXswj9JRZAPRwtTfS4CNRqpKIs-28rNHiPAo="
}
]
}
Public Keys
Generated with $key->getPublicKey()->toString('JWK')
.
{
"keys": [
{
"kty": "EC",
"crv": "P-256",
"x": "rPJyxEu2_oKCrJaaTVTrq39DKJ2XcN6W-k8UvGf-Y_k=",
"y": "Q1jWxYrUKHGm7A1L0jdHnRx91Cj-UD08-HDpciDzK10="
}
]
}
XML
Public Keys
Regular ECDSAKeyValues
Generated with $key->getPublicKey()->toString('XML')
.
<ECDSAKeyValue xmlns="http://www.w3.org/2009/xmldsig11#">
<NamedCurve URI="urn:oid:1.2.840.10045.3.1.7" />
<PublicKey>BKzycsRLtv6CgqyWmk1U66t/Qyidl3DelvpPFLxn/mP5Q1jWxYrUKHGm7A1L0jdHnRx91Cj+UD08+HDpciDzK10=</PublicKey>
</ECDSAKeyValue>
RFC4050 formatted ECDSAKeyValues
Generated by doing \phpseclib3\Crypt\EC\Formats\Keys\XML::enableRFC4050Syntax()
and then $key->getPublicKey()->toString('XML')
.
<ECDSAKeyValue xmlns="http://www.w3.org/2001/04/xmldsig-more#">
<DomainParameters>
<NamedCurve URN="urn:oid:1.2.840.10045.3.1.7" />
</DomainParameters>
<PublicKey>
<X Value="78226179037204970007758573525096590005539509111629919618136274592348755616761" />
<Y Value="30461925696227425434068699083275029164946463271650913121991290383387057138525" />
</PublicKey>
</ECDSAKeyValue>