我有一个sign.pfx文件,我需要从中提取私钥。与直接在命令行中使用openssl相比,使用Ruby / Openssl会得到错误的密钥。有什么建议吗? 谢谢。
使用外壳:
uploadImage();
function getImage(){
var email = GmailApp.search("subject:(EMAIL WITH IMAGE)")[0].getMessages[0];
var attachment = email.getAttachments()[0];
var blob = att.copyBlob();
return blob;
}
function uploadImage(){
// ... SUCCESSFUL AUTHENTICATION OCCURS
var postPayload = {
"file": getImage()
}
var params = {
"payload": JSON.stringify(postPayload),
"contentType": "image/jpeg",
"method": "POST",
"headers" : { "Authorization" : "Bearer XXXXXXXXXXXXXXXXXXXX",
"Content-Disposition": "attachment; filename=test.jpg"}
};
var response = UrlFetchApp.fetch('http://mydomainname.com/wp-json/wp/v2/media/', params);
return response
}
这给了我
openssl pkcs12 -in sign.pfx -out file_private.pem -nocerts -nodes
使用Ruby:
-----BEGIN PRIVATE KEY-----
MIIEwAI...
给出:
OpenSSL::PKCS12.new(File.read(path), password).key.to_s
更新 经过研究,似乎我的问题是,如何在Ruby Openssl gem中使用它
-----BEGIN RSA PRIVATE KEY-----
MIIEpgI...
此命令将RSA密钥(PKCS#1)转换为私钥(PKCS#8)。