In order to create GitHub releases from Travis CI, you need to use public keys they provide to encrypt secrets which can be checked into a project.
I've successfully managed to do this using the openssl crate (v0.10.11):
extern crate base64;
extern crate openssl;
use openssl::rsa::{Padding, Rsa};
use std::{error, fs};
fn main() -> Result<(), Box<dyn error::Error>> {
let data = b"some data";
let pub_key = fs::read_to_string("./key.pem")?; // Read the public key.
let rsa = Rsa::public_key_from_pem(pub_key.as_bytes())?;
let mut res = vec![0; rsa.size() as usize];
rsa.public_encrypt(data, &mut res, Padding::PKCS1)?;
let encrypted = base64::encode(&res);
println!("Encrypted Data: \n{}", encrypted);
Ok(())
}
However, using OpenSSL comes with a few tradeoffs. Most notably: getting cross platform builds to work requires some work.
I've been looking at rustls as an alternative, and was wondering what the equivalent of the code above is.