Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active January 14, 2016 14:01
Show Gist options
  • Save jeroen/57d1304f9e40f4577cd4 to your computer and use it in GitHub Desktop.
Save jeroen/57d1304f9e40f4577cd4 to your computer and use it in GitHub Desktop.
Encrypt with github key
# Send Gabor an encrypted message
library(openssl)
library(jsonlite)
# Get Gabor's pubkey
keydata <- fromJSON("https://api.github.com/users/gaborcsardi/keys")
cat("Number of keys:", nrow(keydata), "\n")
pubkey <- read_pubkey(textConnection(keydata$key[1]))
print(pubkey)
# Encrypt a short secret
mysecret <- charToRaw("This is a secret")
msg <- base64_encode(rsa_encrypt(mysecret, pubkey))
# Gabor has the corresponding private key:
key <- read_key("~/.ssh/id_rsa")
rawToChar(rsa_decrypt(base64_decode(msg), key))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment