Hedera
Search…
Import an existing key
Construct keys in another format to a key representation or import keys from a file.
V2
V1
Method
Type
Description
PrivateKey.fromString(<privateKey>)
String
Constructs a private key string to PrivateKey
PublicKey.fromString(<publicKey>)
String
Constructs a public key string to PublicKey
PrivateKey.fromStringECDSA(<privateKey>)
String
Constructs an ECDSA key from a private key string
PublicKey.fromStringECDSA(<publicKey>)
String
Constructs an ECDSA public key from a public key string
PrivateKey.fromBytesECDSA(<privateKey>)
byte[ ]
Constructs an ECDSA key from a private key bytes
PublicKey.fromBytesECDSA(<publicKey>)
byte[ ]
Constructs an ECDSA public key from a public key bytes
PrivateKey.fromStringED25519(<privateKey>)
String
Constructs an ED25519 key from a private key string
PublicKey.fromStringED25519(<publicKey>)
String
Constructs an ED25519 public key from a public key string
PrivateKey.fromBytesED25519(<privateKey>)
byte [ ]
Constructs an ED25519 key from a private key bytes
PublicKey.fromBytesED25519(<publiceKey>)
byte [ ]
Constructs an ED25519 public key from a public key bytes
PrivateKey.fromBytes(<privateKey>)
byte [ ]
Constructs a private key from bytes to PrivateKey
PublicKey.fromBytes(<publicKey>)
byte [ ]
Contructs a public key from bytes to PublicKey
PrivateKey.fromPem(<pemEncoded>)
String
Parse a private key from a PEM encoded string
PrivateKey.fromPem(<encodedPem, password>)
String, String
Parse a private key from a PEM encoded string. The private key may be encrypted, e.g. if it was generated by OpenSSL.
PrivateKey.readPem(<pemfile>)
Reader
Parse a private key from a PEM encoded reader
PrivateKey.readPem(<pemFile, password>)
Reader, String
Parse a private key from a PEM encoded stream. The key may be encrypted, e.g. if it was generated by OpenSSL.
Java
1
//Converts a private key string to PrivateKey
2
PrivateKey privateKey = PrivateKey.fromStringED25519("302e020100300506032b657004220420d763df96caaabf192c67326e87c32a1ae4571f739022c77d2acaae5dd09cfb13");
3
​
4
//The public key associated with the private key
5
PublicKey publicKey = PublicKey.fromStringED25519("302a300506032b65700321008f556741dcb5e144e5cabfce5355ad5050ec7a6ea15787a5fd759d616e047d24");
6
​
Copied!
JavaScript
1
//Converts a private key string to PrivateKey
2
const privateKey = PrivateKey.fromStringED25519("302e020100300506032b657004220420d763df96caaabf192c67326e87c32a1ae4571f739022c77d2acaae5dd09cfb13");
3
​
4
//The public key associated with the private key
5
const publicKey = PublicKey.fromStringED25519("302a300506032b65700321008f556741dcb5e144e5cabfce5355ad5050ec7a6ea15787a5fd759d616e047d24");
6
​
Copied!
Go
1
//Converts a private key string to PrivateKey
2
privateKey, err := hedera.PrivateKeyFromStringEd25519("302e020100300506032b65700422042012a4a4add3d885bd61d7ce5cff88c5ef2d510651add00a7f64cb90de3359b105")
3
​
4
if err != nil {
5
panic(err)
6
}
7
​
8
//The public key associated with the private key
9
publicKey, err := hedera.PublicKeyFromString("302a300506032b6570032100d292412f1c86507224c1db656050c2162c91983540d608f6a31e9b43359bc5e")
10
​
11
if err != nil {
12
panic(err)
13
}
Copied!
Method
Type
Description
PrivateKey.fromString(<privateKey>)
String
Converts a private key string to PrivateKey
PublicKey.fromString(<publicKey>)
String
Converts a public key string to PublicKey
PrivateKey.fromBytes(<privateKey>)
byte []
Converts a private key from bytes to PrivateKey
PublicKey.fromBytes(<publicKey>)
byte [ ]
Converts a public key from bytes to PublicKey
PrivateKey.fromKeystore(<bytes, passphrase>)
byte [ ], String
Private key from keystore and passphrase
PrivateKey.fromPem(<pemEncoded>)
String
Private key from pem encoded String
PrivateKey.fromPem(<pem, passphrase>)
String, String
Parse a private key from a PEM encoded string. The private key may be encrypted, e.g. if it was generated by OpenSSL.
Java
1
//Converts a private key string to PrivateKey
2
Ed25519PrivateKey privateKey = Ed25519PrivateKey.fromString("302e020100300506032b6570042204201d5b7516488d7010e3730ab7432f7115a7588ad76553153f6e108c62cbd1ff25");
3
​
4
//The public key associated with the private key
5
Ed25519PublicKey publicKey = Ed25519PublicKey.fromString("302a300506032b6570032100d292412f1c86507224c1db656050c2162c91983540d608f6a31e9b43359bc5e");
6
​
7
//v1.3.2
Copied!
JavaScript
1
//Converts a private key string to PrivateKey
2
const privateKey = Ed25519PrivateKey.fromString("302e020100300506032b6570042204201d5b7516488d7010e3730ab7432f7115a7588ad76553153f6e108c62cbd1ff25");
3
​
4
//The public key associated with the private key
5
const publicKey = Ed25519PublicKey.fromString("302a300506032b6570032100d292412f1c86507224c1db656050c2162c91983540d608f6a31e9b43359bc5e");
6
​
7
//v1.4.4
Copied!

​

Copy link
Contents