Last active
January 22, 2021 16:38
-
-
Save YuzuRyo61/377d1b88a20011d32a5ffd297f56b120 to your computer and use it in GitHub Desktop.
RSAキーペアを作ってそれをテキスト形式にするRustスクリプト
This file contains 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
[package] | |
name = "rsa_pem_test" | |
version = "0.1.0" | |
authors = ["YuzuRyo61"] | |
edition = "2018" | |
[dependencies] | |
bcrypt = "*" | |
openssl = "*" | |
pem = "*" |
This file contains 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
extern crate openssl; | |
extern crate pem; | |
use openssl::rsa::Rsa; | |
use pem::{Pem, encode}; | |
fn main() { | |
let rsa = Rsa::generate(2048).unwrap(); | |
// 無駄な変数をすぐに破棄するように改良 | |
let pem_pri_string = { | |
let pem_rsa_pri = Pem { | |
tag: String::from("RSA PRIVATE KEY"), | |
contents: rsa.private_key_to_pem().unwrap() | |
}; | |
encode(&pem_rsa_pri) | |
}; | |
let pem_pub_string = { | |
let pem_rsa_pub = Pem { | |
tag: String::from("PUBLIC KEY"), | |
contents: rsa.public_key_to_pem().unwrap() | |
}; | |
encode(&pem_rsa_pub) | |
}; | |
println!("{}", pem_pri_string); | |
println!("{}", pem_pub_string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment