stacks-network / key-encoder-js Goto Github PK
View Code? Open in Web Editor NEWLibrary for encoding and decoding ecdsa private keys and converting between formats
License: MIT License
Library for encoding and decoding ecdsa private keys and converting between formats
License: MIT License
I am creating keypairs in android and ios native and I am not able to get eos-js able to verify the signatures.
Is it possible to import the keypairs as DER / PEM?
I need to make pem encoded secp256k1 keys.
I do this:
var KeyEncoder = require('key-encoder'),
keyEncoder = new KeyEncoder('secp256k1')
How I create raw keys from here?
I first have to make these raw keys from here and then encode them in Pem format with keyEncoder.encodePrivate and keyEncoder.encodePublic?
I'm trying to use the library, but can't even get started due to an error: "TypeError: KeyEncoder is not a constructor"
To reproduce:
var KeyEncoder = require('key-encoder'),
keyEncoder = new KeyEncoder('secp256k1')
Result:
keyEncoder = new KeyEncoder('secp256k1')
^
TypeError: KeyEncoder is not a constructor
Expected result: No output.
I'm trying to convert ethereum private key to DER format but get an error. Below are the steps:
First I use web3 to create new ethereum account that has the following key:
private key = 0x45a84f0899393274a9aa0ba3b86277543fc7f3ac508390a3b492fb88ac189dd1
Run key-encoder code:
var KeyEncoder = require('key-encoder').default,
keyEncoder = new KeyEncoder('secp256k1')
var rawPrivateKey = '0x45a84f0899393274a9aa0ba3b86277543fc7f3ac508390a3b492fb88ac189dd1',
var pemPrivateKey = keyEncoder.encodePrivate(rawPrivateKey, 'raw', 'pem', 'pkcs8') //default is 'pkcs1'
console.log(pemPrivateKey)
It outputs:
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIEWoTwiZOTJ0qaoLo7hid1Q/x/OsUIOQo7SS+4isGJ3RoAcGBSuBBAAK
oUQDQgAEQ29JqkXW6Bi9Hq1n2frYRNDnt5LUivt6lH36sXh61b4rQADSMvagnjlx
R0zS2n8Ue5t0bm/1W3h63JOCC68N5w==
-----END EC PRIVATE KEY-----
I save it to eth_private.pem
file. Then I try to use openssl tool to covnert it to DER with this command:
openssl pkcs8 -inform PEM -outform DER -topk8 -nocrypt -in eth_private.pem -out eth_private.der
It raises this error:
unable to load key
4669285888:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto/asn1/tasn_dec.c:1149:
4669285888:error:0D07803A:asn1 encoding routines:asn1_item_embed_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:309:Type=X509_ALGOR
4669285888:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto/asn1/tasn_dec.c:646:Field=pkeyalg, Type=PKCS8_PRIV_KEY_INFO
4669285888:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto/pem/pem_pkey.c:88:
I'm not sure if the problem with the private key cause it works when I try the private key in project sample.
i am creating keyPair using elliptical-secp253k1 like:--
ec.genKeyPair();
When i print keyPair on console it shows -->
<Key priv: c55388432e65ecdf6cd89a11efdcbcdf823764c2b019fe0b99305590ea7352a9 pub: >
Question 1: what type of object is this? (its not a JSON object. converting it to JSON generates a big output.)
Question 2:how to save this pair in database or pem & load it later?
Please help.
Thank you!
Hyperledger Fabric uses secp256r1 curve. The keys returned as part of fabric SDK are in raw but they need conversion to hex.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.