29void WriteKey(
const KeyInfo& key,
const std::string& file_name) {
31 assert(key.SerializeToString(&str));
33 printf(
"save key to path %s\n", file_name.c_str());
34 int fd = open(file_name.c_str(), O_WRONLY | O_CREAT, 0666);
36 printf(
"open file fail %s\n", strerror(errno));
39 write(fd, str.c_str(), str.size());
43int main(
int argc,
char** argv) {
44 std::string type =
"ED25519";
45 std::string path =
"./";
47 printf(
"<path> [type](RSA|AES|ED25519(default))\n");
55 SignatureInfo::HashType hash_type;
57 hash_type = SignatureInfo::RSA;
58 }
else if (type ==
"AES") {
59 hash_type = SignatureInfo::CMAC_AES;
60 }
else if (type ==
"ED25519") {
61 hash_type = SignatureInfo::ED25519;
63 printf(
"type invalid\n");
70 assert(key.SerializeToString(&str));
73 KeyInfo pub_info, pri_info;
74 pub_info.set_key(key.public_key());
75 pub_info.set_hash_type(key.hash_type());
77 pri_info.set_key(key.private_key());
78 pri_info.set_hash_type(key.hash_type());
80 WriteKey(pri_info, path +
".key.pri");
81 WriteKey(pub_info, path +
".key.pub");