Created
          December 7, 2016 14:02 
        
      - 
      
- 
        Save jeroen/1ffbfbdad40f4aad6657c337a4924f0e to your computer and use it in GitHub Desktop. 
    Encrypt using Github public key
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | github_pubkey <- function(user){ | |
| url <- sprintf("https://api.github.com/users/%s/keys", user) | |
| keys <- jsonlite::fromJSON(url) | |
| lapply(keys$key, openssl::read_pubkey) | |
| } | |
| # Get pubkey from Gabor | |
| gabor <- github_pubkey('gaborcsardi') | |
| pubkey <- gabor[[1]] #has 3 keys, use first one | |
| # Example of old repo | |
| buf <- openssl::rsa_encrypt(charToRaw("My secret token"), pubkey) | |
| openssl::base64_encode(buf) | |
Note that you can use my_key() instead of read_key("~/.ssh/id_rsa").
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Gabor used the above workflow to send me a GitHub access token we needed to share. This token played the role of "My secret token" and he looked up and encrypted with my public key from GitHub.
Here's how I got the token back out again!