<p>OpenSSL's RNG is considered secure, so there should be no problem with this method. I don't think you need to use <code>-rand /dev/urandom</code> since OpenSSL already uses <code>/dev/urandom</code> for seeding the RNG.</p>

CC BY-SA 3.0
2017-07-15T00:54:59.570Z
Makes sense, tnx
Mircea Stanciu
CC BY-SA 3.0
2017-12-18T23:31:01.840Z
If you're on macOS, which uses LibreSSL 2.2.7, then there is no option `-rand`
onmyway133
CC BY-SA 3.0
2017-07-15T00:33:27.803Z
2017-07-15T00:33:27.803Z
Ava Chow
<p>I am building a script to generate secp256k1 using OpenSSL in MacOS.
Seems to work fine.
My question: is this SECURE enough?</p>

<pre><code>#!/bin/bash

if [ $# -eq 0 ]; then
  echo "Missing name, for example generate_key.sh bob"
  exit 1
fi

FILE_NAME=$1
PRIVATE_KEY=${FILE_NAME}_private.pem
PUBLIC_KEY=${FILE_NAME}_public.pem
BITCOIN_PRIVATE_KEY=bitcoin_${FILE_NAME}_private.key
BITCOIN_PUBLIC_KEY=bitcoin_${FILE_NAME}_public.key

echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out $PRIVATE_KEY

echo "Generating public key"
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEY

echo "Generating BitCoin private key"
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 &gt; $BITCOIN_PRIVATE_KEY

echo "Generating BitCoin public key"
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 &gt; $BITCOIN_PUBLIC_KEY

echo "Files created!"
</code></pre>

CC BY-SA 3.0
2017-09-14T17:37:20.943Z
Could you may explain what's the background of converting the private/public keys to Bitcoin private/public keys?
soupdiver
<openssl>
OpenSSL generate Bitcoin address
Mircea Stanciu
# OpenSSL generate Bitcoin address

(Asked by: username_0 on 2017-07-15)

I am building a script to generate secp256k1 using OpenSSL in MacOS.
Seems to work fine.
My question: is this SECURE enough?
#!/bin/bash

if [ $# -eq 0 ]; then
  echo "Missing name, for example generate_key.sh bob"
  exit 1
fi

FILE_NAME=$1
PRIVATE_KEY=${FILE_NAME}_private.pem
PUBLIC_KEY=${FILE_NAME}_public.pem
BITCOIN_PRIVATE_KEY=bitcoin_${FILE_NAME}_private.key
BITCOIN_PUBLIC_KEY=bitcoin_${FILE_NAME}_public.key

echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out $PRIVATE_KEY

echo "Generating public key"
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEY

echo "Generating BitCoin private key"
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 > $BITCOIN_PRIVATE_KEY

echo "Generating BitCoin public key"
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEY

echo "Files created!"

**Tags:** openssl

> **Comments:**
> **username_1**: Could you may explain what's the background of converting the private/public keys to Bitcoin private/public keys?  

---

## 1 answers

### Answer by username_2 on 2017-07-15. Score: 2

OpenSSL's RNG is considered secure, so there should be no problem with this method. I don't think you need to use `-rand /dev/urandom` since OpenSSL already uses `/dev/urandom` for seeding the RNG.

> **Comments:**
> **username_0**: Makes sense, tnx  
> **username_3**: If you're on macOS, which uses LibreSSL 2.2.7, then there is no option `-rand`  

---

