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.KeyStorekeyStoreprotected java.lang.StringkeyStoreFileprotected static org.slf4j.Loggerloggerprotected java.lang.Stringpassword -
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.PrivateKeyconvertHexedStringToPrivateKey(java.lang.String hexedPrivateKey, java.lang.String curveName)convert hexed string into PrivateKey type storePublicKeyWithPemstatic java.security.PrivateKeyconvertHexedStringToPrivateKey(java.math.BigInteger privateKey, java.lang.String curveName)static java.lang.StringgetHexedPrivateKey(java.security.PrivateKey privateKey)java.lang.StringgetHexedPublicKey()static java.lang.StringgetHexedPublicKey(java.security.PublicKey publicKey)java.security.KeyPairgetKeyPair()get keyPair loaded from the keyStore filejava.lang.StringgetKeyStoreFile()protected abstract java.security.PrivateKeygetPrivateKey()protected abstract java.security.PublicKeygetPublicKey()protected java.security.PublicKeygetPublicKeyFromPrivateKey()static java.security.PublicKeygetPublicKeyFromPrivateKey(java.security.PrivateKey privateKey)protected voidload()load information from the keyStoreFileprotected abstract voidload(java.io.InputStream in)static voidstorePublicKeyWithPem(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
-