---
title: "mac 上生成 RSA"
author: "friping"
date: "2014-05-18T13:02:10Z"
tags: []
categories: ["操作系统"]
slug: "mac-rsa"
draft: false
lastmod: "2014-05-18T13:02:56Z"
id: 2067867
url: "https://friping.iteye.com/blog/2067867"
---

1：让openssl随机生成了一份私钥，加密长度是1024位

```
openssl genrsa -out rsa_private_key.pem 1024
```

 

2：根据私钥生成公钥

```
openssl rsa -in rsa_private_key.pem -out rsa_public_key.pem -pubout
```

 

3：私钥还不能直接被使用，需要进行PKCS#8编码

 

```
openssl pkcs8 -topk8 -in rsa_private_key.pem -out pkcs8_rsa_private_key.pem -nocrypt
```