Class KeyTool
java.lang.Object
org.fisco.bcos.sdk.crypto.keystore.KeyTool
- Direct Known Subclasses:
P12KeyStore
,PEMKeyStore
public abstract class KeyTool
extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description protected java.security.KeyStore
keyStore
protected java.lang.String
keyStoreFile
protected static org.slf4j.Logger
logger
protected java.lang.String
password
-
Constructor Summary
Constructors Constructor Description KeyTool(java.io.InputStream keyStoreFileInputStream)
constructor for PEM with key file input streamKeyTool(java.io.InputStream keyStoreFileInputStream, java.lang.String password)
constructor for the P12: with password and key file input streamKeyTool(java.lang.String keyStoreFile)
constructor for PEM without passwordKeyTool(java.lang.String keyStoreFile, java.lang.String password)
constructor for the P12: with password -
Method Summary
Modifier and Type Method Description static java.security.PrivateKey
convertHexedStringToPrivateKey(java.lang.String hexedPrivateKey, java.lang.String curveName)
convert hexed string into PrivateKey type storePublicKeyWithPemstatic java.security.PrivateKey
convertHexedStringToPrivateKey(java.math.BigInteger privateKey, java.lang.String curveName)
static java.lang.String
getHexedPrivateKey(java.security.PrivateKey privateKey)
java.lang.String
getHexedPublicKey()
static java.lang.String
getHexedPublicKey(java.security.PublicKey publicKey)
java.security.KeyPair
getKeyPair()
get keyPair loaded from the keyStore filejava.lang.String
getKeyStoreFile()
protected abstract java.security.PrivateKey
getPrivateKey()
protected abstract java.security.PublicKey
getPublicKey()
protected java.security.PublicKey
getPublicKeyFromPrivateKey()
static java.security.PublicKey
getPublicKeyFromPrivateKey(java.security.PrivateKey privateKey)
protected void
load()
load information from the keyStoreFileprotected abstract void
load(java.io.InputStream in)
static void
storePublicKeyWithPem(java.security.PrivateKey privateKey, java.lang.String privateKeyFilePath)
-
Field Details
-
logger
protected static org.slf4j.Logger logger -
keyStoreFile
protected final java.lang.String keyStoreFile -
password
protected final java.lang.String password -
keyStore
protected java.security.KeyStore keyStore
-
-
Constructor Details
-
KeyTool
public KeyTool(java.lang.String keyStoreFile, java.lang.String password)constructor for the P12: with password- Parameters:
keyStoreFile
- the path of the keystore filepassword
- password to read the keystore file
-
KeyTool
public KeyTool(java.lang.String keyStoreFile)constructor for PEM without password- Parameters:
keyStoreFile
- the path of the keystore file
-
KeyTool
public KeyTool(java.io.InputStream keyStoreFileInputStream, java.lang.String password)constructor for the P12: with password and key file input stream- Parameters:
keyStoreFileInputStream
- the input stream of the keystore filepassword
- password to read the keystore file
-
KeyTool
public KeyTool(java.io.InputStream keyStoreFileInputStream)constructor for PEM with key file input stream- Parameters:
keyStoreFileInputStream
- the input stream of the keystore file
-
-
Method Details
-
getPrivateKey
protected abstract java.security.PrivateKey getPrivateKey() -
getKeyStoreFile
public final java.lang.String getKeyStoreFile() -
getKeyPair
public java.security.KeyPair getKeyPair()get keyPair loaded from the keyStore file- Returns:
- the keyPair
-
getPublicKey
protected abstract java.security.PublicKey getPublicKey() -
getHexedPublicKey
public static java.lang.String getHexedPublicKey(java.security.PublicKey publicKey) -
getHexedPublicKey
public java.lang.String getHexedPublicKey() -
getHexedPrivateKey
public static java.lang.String getHexedPrivateKey(java.security.PrivateKey privateKey) -
convertHexedStringToPrivateKey
public static java.security.PrivateKey convertHexedStringToPrivateKey(java.lang.String hexedPrivateKey, java.lang.String curveName) throws LoadKeyStoreExceptionconvert hexed string into PrivateKey type storePublicKeyWithPem- Parameters:
hexedPrivateKey
- the hexed privateKeycurveName
- the curve name- Returns:
- the converted privateKey
- Throws:
LoadKeyStoreException
- convert exception, return exception information
-
convertHexedStringToPrivateKey
public static java.security.PrivateKey convertHexedStringToPrivateKey(java.math.BigInteger privateKey, java.lang.String curveName) throws LoadKeyStoreException- Throws:
LoadKeyStoreException
-
storePublicKeyWithPem
public static void storePublicKeyWithPem(java.security.PrivateKey privateKey, java.lang.String privateKeyFilePath) throws java.io.IOException- Throws:
java.io.IOException
-
load
protected abstract void load(java.io.InputStream in) -
load
protected void load()load information from the keyStoreFile -
getPublicKeyFromPrivateKey
protected java.security.PublicKey getPublicKeyFromPrivateKey() -
getPublicKeyFromPrivateKey
public static java.security.PublicKey getPublicKeyFromPrivateKey(java.security.PrivateKey privateKey) throws LoadKeyStoreException- Throws:
LoadKeyStoreException
-