New In Cryptography

Dariia Porechna, Wolfram Research

ABSTRACT

Information security and protection are becoming increasingly vital in the modern world of computer systems, making cryptography an indispensable tool. Version 12 of the Wolfram Language continues to grow its coverage of methods for both symmetric (shared secret key) and asymmetric (public/private key pair) cryptography to ensure confidentiality, data integrity and authenticity of encrypted and/or digitally signed data of various formats, as well as arbitrary Wolfram Language expressions.
This talk will cover key generation and management, explain purposes and usage differences between hashing, encryption and digital signatures and list which algorithms in those topics are supported in Wolfram Language, as well as announce planned development for future versions.

Let's talk!

Setting up a simple page for sending encrypted messages. It that has a public key built in, and once the message  is submitted it’gets encrypted and stored in a databin.

Generating a key pair:

binkeys=GenerateAsymmetricKeyPair["RSA"]

Creating a databin:

bin= CreateDatabin[]

Creating and deploying the function to encrypt and send to databin:

function=With[{public=binkeys["PublicKey"], bin = bin},
FormFunction[{"message","Enter a message: "}->"String",
Function[(DatabinAdd[bin,Encrypt[public,#message]];"Thank you!")]]];

obj = CloudDeploy[function,CloudObject["create-encrypted-message"],Permissions->"Public"]

Scan the barcode to access it from your smartphone:

BarcodeImage[obj[[1]],"QR"]

In the end of the talk I will decrypt those messages with the private key.

So what can we do with Cryptography?

Hash data

Generate symmetric and asymmetric keys

Derive strong and secure keys from weaker passwords

Encrypt data, including arbitrary Wolfram Language expressions and files

Digitally sign data using RSA or elliptic curve cryptography

Compute cryptocurrency-compatible keys and digital signatures

Hash

Hash any Wolfram Language expression

plot = Plot3D[Sin[x+y^2],{x,-3,3},{y,-2,2}]

Hash[plot,"Keccak256","HexString"]

Hash files of various formats

ocelot =Import["ExampleData/ocelot.jpg"]

file1 = FindFile["ExampleData/ocelot.jpg"];

FileHash[file1, "SHA256",All, "Base64Encoding"]

file2 = FindFile["ExampleData/classification.tsv"];

Snippet[File[file2]]

FileHash[file2, "RIPEMD160", All, "ByteArray"]

Key generation and derivation

Generate a secret key for symmetric ciphers (DES, AES, Blowfish, etc.):

GenerateSymmetricKey[]

Generate a pair of private and public keys for asymmetric algorithms:

GenerateAsymmetricKeyPair["RSA"]

GenerateAsymmetricKeyPair["EllipticCurve"]

Construct keys from existing values:

(* version 12.1 example *)

PrivateKey[<|"Type"->"EllipticCurve","PrivateHexString"->"E9873D79C6D87DC0FB6A5778633389F4453213303DA61F20BD67FC233AA33262"|>]

PublicKey[%]

Derive a secure pseudorandom key of larger size using scrypt or Argon2:

Because people are not good in creating long random passwords - they are usually short, often reused and vulnerable to attacks. Key derivation strengthens the key by making it harder to compute hash and increasing the search space. Key derivation functions are used in password hashing and verification (authentication).

dkey = GenerateDerivedKey["password"]

Encryption

Using symmetric algorithms

ocelot = ;

GenerateSymmetricKey[]

Encrypt[symkey, ocelot]

Decrypt[symkey,%]

Using RSA

rsakeys=GenerateAsymmetricKeyPair["RSA"]

Encrypt[rsakeys["PublicKey"], "WTC2019 test message"]

Decrypt[rsakeys["PrivateKey"],%]

Encrypt files using  a password

File encryption helps keep your sensitive data, research or computation results secret from all but those who are authorized to see it.

data=ExampleData[{"Dataset","Titanic"}];
RandomSample[data,5]

Export["mydata.tsv",data]

Safely encrypt the file by typing your password in an interactive authentication dialog.

EncryptFile[AuthenticationDialog["Password",#Password&],"mydata.tsv"]

Delete the original file.

DeleteFile["mydata.tsv"]

When you wish to access your data next time, simply decrypt it using the same password.

DecryptFile[AuthenticationDialog["Password",#Password&],"mydata.tsv.mx"]

Import the file semantically to continue with it as a Dataset object.

data=SemanticImport["mydata.tsv"]

Digital signatures

Digital signature is dependent on the information signed, and thus its fundamental advantage over the handwritten signatures is the ability to detect the slightest changes in the information signed, invisible to the human eye.

spikey =;

keys = GenerateAsymmetricKeyPair["EllipticCurve"]

Create the digital signature for the image:

sig = GenerateDigitalSignature[spikey, keys["PrivateKey"]]

Check the validity of the signature:

VerifyDigitalSignature[{spikey, sig}, keys["PublicKey"]]

For comparison, check the signature for a different image:

VerifyDigitalSignature[{, sig}, keys["PublicKey"]]

The image below looks the same as the original image, but in fact it’s not:

VerifyDigitalSignature[{, sig}, keys["PublicKey"]]

Let's see your messages!

Pull the entries from the databin:

bin

messages =Values[bin]

Decrypt them with the private key:

Decrypt[binkeys["PrivateKey"], #]&/@messages//Column