- 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
PublicKey[assoc]
represents the public part of a key pair for a public-key cryptographic system.
PublicKey[PrivateKey[…]]
creates a matching public key for the given private key.
PublicKey
PublicKey[assoc]
represents the public part of a key pair for a public-key cryptographic system.
PublicKey[PrivateKey[…]]
creates a matching public key for the given private key.
Details
- PublicKey objects can be used with functions such as Encrypt, Decrypt and VerifyDigitalSignature.
- Data encrypted with a particular PublicKey object must be decrypted with a corresponding PrivateKey object.
- Corresponding pairs of PrivateKey and PublicKey objects can be generated with GenerateAsymmetricKeyPair.
- PublicKey[…]["prop"] can be used to extract properties of the public key.
- Basic properties for PublicKey include:
-
"Type" type of cryptography "PublicByteArray" public key as a byte array "PublicHexString" public key as a hex string "PublicKeySize" size of public key in bits - Possible types of cryptography include "RSA" and "EllipticCurve".
- Additional properties for "RSA" include:
-
"PublicExponent" public exponent "PublicModulus" public modulus "Padding" padding mode - Additional properties for "EllipticCurve" include:
-
"CurveName" name of elliptic curve (e.g. "sec256k1") "PublicCurvePoint" public curve point "Compressed" whether the public key is in compressed form - Possible settings for "CurveName" are listed in $CryptographicEllipticCurveNames.
- PublicKey[…]["Parameters"] gives all the information contained in the object, as an association.
- PublicKey[…]["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 public key:
keys = GenerateAsymmetricKeyPair["EllipticCurve"]Check the elliptic curve used to create the key pair:
keys["PublicKey"]["CurveName"]Check if the public key was compressed:
keys["PublicKey"]["Compressed"]Discover all available properties of the public key:
keys["PublicKey"]["Properties"]Scope (2)
You can use PublicKey as a constructor for a valid public key object.
Generate public and private keys:
keys = GenerateAsymmetricKeyPair[]public = keys["PublicKey"];Construct a valid public key object from the pre-generated values:
PublicKey[<|"Type" -> "RSA", "PublicExponent" -> public["PublicExponent"], "PublicModulus" -> public["PublicModulus"]|>]Test whether it matches the original key:
SameQ[%, public]You can construct a public key from a private key.
private = GenerateAsymmetricKeyPair[]["PrivateKey"]Use PublicKey to construct a corresponding public key object:
PublicKey[private]Properties & Relations (2)
PublicKey objects created by GenerateAsymmetricKeyPair contain a complete set of properties for the key:
ec1 = GenerateAsymmetricKeyPair["EllipticCurve"]["PublicKey"]ec1["Properties"]It is not necessary to provide all properties to reconstruct a valid public key object. For an elliptic curve, it is sufficient to specify only the public curve point:
ec2 = PublicKey[<|"Type" -> "EllipticCurve", "PublicCurvePoint" -> ec1["PublicCurvePoint"]|>]Verify that the keys are identical:
SameQ[ec1, ec2]Alternatively, use a hex string representation of the public curve point:
ec3 = PublicKey[<|"Type" -> "EllipticCurve", "PublicHexString" -> ec1["PublicHexString"]|>]Verify that all keys are identical:
SameQ[ec1, ec2, ec3]Use a ByteArray representation:
ec4 = PublicKey[<|"Type" -> "EllipticCurve", "PublicByteArray" -> ec1["PublicByteArray"]|>]Verify that all keys are identical:
SameQ[ec1, ec2, ec3, ec4]To reconstruct a PublicKey object for RSA, provide the public modulus in integer, hex or ByteArray representations:
rsa1 = GenerateAsymmetricKeyPair["RSA"]["PublicKey"];Recreate the same object as initially obtained from GenerateAsymmetricKeyPair:
rsa2 = PublicKey[<|"Type" -> "RSA", "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), PublicKey, Wolfram Language function, https://reference.wolfram.com/language/ref/PublicKey.html (updated 2020).
CMS
Wolfram Language. 2015. "PublicKey." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/PublicKey.html.
APA
Wolfram Language. (2015). PublicKey. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PublicKey.html
BibTeX
@misc{reference.wolfram_2026_publickey, author="Wolfram Research", title="{PublicKey}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/PublicKey.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_publickey, organization={Wolfram Research}, title={PublicKey}, year={2020}, url={https://reference.wolfram.com/language/ref/PublicKey.html}, note=[Accessed: 12-June-2026]}