Use Asymmetric Key Cryptography
Asymmetric key encryption requires the generation of a public and private key, allowing the message to be encrypted with a "public" key but only decrypted using a "private" key.
Generate an asymmetric key pair.
In[1]:=
![Click for copyable input](assets.en/use-asymmetric-key-cryptography/In_28.png)
keys = GenerateAsymmetricKeyPair[]
Out[1]=
![](assets.en/use-asymmetric-key-cryptography/O_23.png)
Encrypt the message using the public key.
In[2]:=
![Click for copyable input](assets.en/use-asymmetric-key-cryptography/In_29.png)
encrypted =
Encrypt[keys["PublicKey"],
"The gold is located off the coast of Honduras."]
Out[2]=
![](assets.en/use-asymmetric-key-cryptography/O_24.png)
The message cannot be decrypted using the public key that encrypted it. The private key must be used.
In[3]:=
![Click for copyable input](assets.en/use-asymmetric-key-cryptography/In_30.png)
Decrypt[keys["PublicKey"], encrypted]
![](assets.en/index.en/M_1.gif)
Out[3]=
![](assets.en/use-asymmetric-key-cryptography/O_25.png)
In[4]:=
![Click for copyable input](assets.en/use-asymmetric-key-cryptography/In_31.png)
Decrypt[keys["PrivateKey"], encrypted]
Out[4]=
![](assets.en/use-asymmetric-key-cryptography/O_26.png)