Skip to main content


Table of Contents


Before we start talking about API methods, there is a need to deal with cryptography issues. This document will give examples of work with cryptography using openssl. Many programming languages are suitable for working with this program, thus the presented examples could be transferred to these languages without any difficulties.

The following version of openssl is used for given examples:

~ openssl version
OpenSSL 1.1.1f 31 Mar 2020

Full example of private and public key generation process

Here is the full example of how to generate the private and public keys:

#! /bin/sh -x

~ openssl version
openssl ecparam -name secp256k1 -genkey -text -out ./key.priv.pem
~ cat ./key.priv.pem
openssl ec -in ./key.priv.pem -pubout -out ./
~ cat ./
~ echo 'test123' > textfile.txt
openssl dgst -sha256 -sign ./key.priv.pem -out ./sign.bin textfile.txt
openssl base64 -in ./sign.bin -out ./sign.txt
~ cat ./sign.txt
openssl dgst -sha256 -verify ./ -signature ./sign.bin ./textfile.txt

~ openssl version
OpenSSL 1.1.0h 27 Mar 2018
~ openssl ecparam -name secp256k1 -genkey -text -out ./key.priv.pem
~ cat ./key.priv.pem
ASN1 OID: secp256k1
~ openssl ec -in ./key.priv.pem -pubout -out ./
read EC key
writing EC key
~ cat ./
-----END PUBLIC KEY-----
~ echo test123
openssl dgst -sha256 -sign ./key.priv.pem -out ./sign.bin textfile.txt
openssl base64 -in ./sign.bin -out ./sign.txt
~ cat ./sign.txt
~ openssl dgst -sha256 -verify ./ -signature ./sign.bin ./textfile.txt
Verified OK

You can find the description of private and public keys in the corresponding sections below.

Private key generation

A private key is necessary for signing any data or documents. This key is the only way to perform any actions with the Power Ecosystem.

Refer to the Private key generation guide to learn how to generate a private key using OpenSSL.

Ensure your private key is securely stored.

Public key generation

The public key is required to verify that the private key signature conforms with the information in the public key. The public key is passed to Power_ecosystem network in the moment of wallet registration. This key is kept in the blockchain and can be accessed by anyone. Use our guide to get the public key as a pair for your private key.

Data Signature

On the line 6 of the example given in How the cryptography works section, a textfile.txt file is created with the contents of test123 (on some operating systems this command could add a newline character):

~ echo 'test123' > textfile.txt

On the next line, the data is signed in the file textfile.txt:

openssl dgst -sha256 -sign ./key.priv.pem -out ./sign.bin textfile.txt

Then, the binary file sign.bin is converted into base64 format (for the example purposes, sign.bin with binary data will be used for signature verification):

openssl base64 -in ./sign.bin -out ./sign.txt

Signature obtained:

~ cat ./sign.txt

Signature verification

To verify the signature, use the following command:

~ openssl dgst -sha256 -verify ./ -signature ./sign.bin ./textfile.txt
Verified OK

Wallet Import Format

The current implementation of the wallet stores keys in WIF format. Here you can find the guidelines for working with this format.

Key Conversion to DER format

In order to register your account, you need to create a compressed public key (such a key that has the Y coordinate in its entirety and the parity of the X coordinate). This key occupies 33 bytes without a header and the first byte here is 2 or 3, depending on the parity of the X coordinate.

Get the DER-formatted key from the private key created by openssl using the following command:

~ openssl ec -in key.priv.pem -conv_form compressed -outform DER | dd bs=1 skip=53 > key.raw.bin

In this example, the dd option removes the first 53 bytes of the data received from an openssl program (it skips ASN.1 header and writes only the key to a file 'key.raw.bin'). The size of the key.raw.bin file should be 33 bytes.