- See Also
-
Related Guides
- Cryptography
- Cryptographic Number Theory
- Working with Tezos Blockchains
- Working with Litecoin Blockchains
- Working with Ethereum Blockchains
- Working with Cardano Blockchains
- Working with bloxberg Blockchain
- Working with Bitcoin Cash Blockchains
- Working with Bitcoin Blockchains
- Working with ARK Blockchains
- Working with Blockchains
-
- See Also
-
Related Guides
- Cryptography
- Cryptographic Number Theory
- Working with Tezos Blockchains
- Working with Litecoin Blockchains
- Working with Ethereum Blockchains
- Working with Cardano Blockchains
- Working with bloxberg Blockchain
- Working with Bitcoin Cash Blockchains
- Working with Bitcoin Blockchains
- Working with ARK Blockchains
- Working with Blockchains
PrivateKey[assoc]
represents the private part of a key pair for a public-key cryptographic system.
PrivateKey
PrivateKey[assoc]
represents the private part of a key pair for a public-key cryptographic system.
Details
- PrivateKey objects can be used with functions such as Encrypt, Decrypt and GenerateDigitalSignature.
- For encryption, data can only be decrypted with a particular PrivateKey object if it was encrypted with the corresponding PublicKey object.
- Corresponding pairs of PrivateKey and PublicKey objects can be generated with GenerateAsymmetricKeyPair.
- PrivateKey[…]["prop"] can be used to extract properties of the private key.
- Basic properties for a PrivateKey include:
-
"Type" type of cryptography "PrivateByteArray" private key as a byte array "PublicByteArray" public key as a byte array "PrivateHexString" private key as a hex string "PublicHexString" public key as a hex string "PrivateKeySize" size of private key in bits "PublicKeySize" size of public key in bits - Possible types of cryptography include "RSA" and "EllipticCurve".
- Additional properties for "RSA" include:
-
"PrivateExponent" private exponent "PublicExponent" public exponent "PublicModulus" public modulus "Padding" padding mode - Additional properties for "EllipticCurve" include:
-
"CurveName" name of elliptic curve (e.g. "sec256k1") "PrivateMultiplier" private multiplier "PublicCurvePoint" public curve point "Compressed" whether the public key is in compressed form - Possible settings for "CurveName" are listed in $CryptographicEllipticCurveNames.
- PrivateKey[…]["Parameters"] gives all the information contained in the object as an association.
- PrivateKey[…]["Properties"] gives a list of available properties.
Examples
open all close allBasic Examples (2)
Generate public and private keys:
keys = GenerateAsymmetricKeyPair[]Encrypt[keys["PublicKey"], "Now is the time..."]Decrypt using the private key:
Decrypt[keys["PrivateKey"], %]Generate an elliptic curve–based private key:
keys = GenerateAsymmetricKeyPair["EllipticCurve"]Check the elliptic curve used to create the key pair:
keys["PrivateKey"]["CurveName"]Discover all available properties of the private key:
keys["PrivateKey"]["Properties"]Scope (2)
You can use PrivateKey as a constructor for a valid private key object.
Generate public and private keys:
keys = GenerateAsymmetricKeyPair[]private = keys["PrivateKey"];Construct a valid private key object from the pre-generated values:
PrivateKey[<|"Type" -> "RSA", "PrivateExponent" -> private["PrivateExponent"], "PublicModulus" -> private["PublicModulus"]|>]Test whether it matches the original key:
SameQ[%, private]Construct a valid PrivateKey object from an existing key provided as a hex string:
hex = "E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262";hexkey = PrivateKey[<|"Type" -> "EllipticCurve", "CurveName" -> "prime256v1", "PrivateHexString" -> hex|>]Equivalently, use the key's integer representation:
int = FromDigits[hex, 16]intkey = PrivateKey[<|"Type" -> "EllipticCurve", "CurveName" -> "prime256v1", "PrivateMultiplier" -> int|>]The object representation will be the same in both cases:
SameQ[intkey, hexkey]Properties & Relations (2)
PrivateKey objects created by GenerateAsymmetricKeyPair contain a complete set of properties for the key:
ec1 = GenerateAsymmetricKeyPair["EllipticCurve"]["PrivateKey"]ec1["Properties"]It is not necessary to provide all properties to reconstruct a valid private key object. For an elliptic curve, it is sufficient to specify only the private multiplier:
ec2 = PrivateKey[<|"Type" -> "EllipticCurve", "PrivateMultiplier" -> ec1["PrivateMultiplier"]|>]Verify that the keys are identical:
SameQ[ec1, ec2]Alternatively, use a hex string representation of the private multiplier:
ec3 = PrivateKey[<|"Type" -> "EllipticCurve", "PrivateHexString" -> ec1["PrivateHexString"]|>]Verify that all keys are identical:
SameQ[ec1, ec2, ec3]Use a ByteArray representation:
ec4 = PrivateKey[<|"Type" -> "EllipticCurve", "PrivateByteArray" -> ec1["PrivateByteArray"]|>]Verify that all keys are identical:
SameQ[ec1, ec2, ec3, ec4]To reconstruct a PrivateKey object for RSA, provide both the private exponent and the public modulus:
rsa1 = GenerateAsymmetricKeyPair["RSA"]["PrivateKey"];Recreate the same object as initially obtained from GenerateAsymmetricKeyPair:
rsa2 = PrivateKey[<|"Type" -> "RSA", "PrivateExponent" -> rsa1["PrivateExponent"], "PublicModulus" -> rsa1["PublicModulus"]|>]Verify that both keys are identical:
SameQ[rsa1, rsa2]Related Guides
-
▪
- Cryptography ▪
- Cryptographic Number Theory ▪
- Working with Tezos Blockchains ▪
- Working with Litecoin Blockchains ▪
- Working with Ethereum Blockchains ▪
- Working with Cardano Blockchains ▪
- Working with bloxberg Blockchain ▪
- Working with Bitcoin Cash Blockchains ▪
- Working with Bitcoin Blockchains ▪
- Working with ARK Blockchains ▪
- Working with Blockchains
Text
Wolfram Research (2015), PrivateKey, Wolfram Language function, https://reference.wolfram.com/language/ref/PrivateKey.html (updated 2020).
CMS
Wolfram Language. 2015. "PrivateKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/PrivateKey.html.
APA
Wolfram Language. (2015). PrivateKey. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PrivateKey.html
BibTeX
@misc{reference.wolfram_2026_privatekey, author="Wolfram Research", title="{PrivateKey}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/PrivateKey.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_privatekey, organization={Wolfram Research}, title={PrivateKey}, year={2020}, url={https://reference.wolfram.com/language/ref/PrivateKey.html}, note=[Accessed: 13-June-2026]}