Package org.xipki.security.util
Class KeyUtil
- java.lang.Object
-
- org.xipki.security.util.KeyUtil
-
public class KeyUtil extends Object
Key utility class.- Since:
- 2.0.0
- Author:
- Lijun Liao (xipki)
-
-
Field Summary
Fields Modifier and Type Field Description static org.bouncycastle.asn1.x509.AlgorithmIdentifierALGID_RSA
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PrivateKeyconvertXDHToDummyEdDSAPrivateKey(PrivateKey key)Convert XDH edwards private key to EdDSA private key.static ECPublicKeycreateECPublicKey(byte[] encodedAlgorithmIdParameters, byte[] encodedPoint)static ECPublicKeycreateECPublicKey(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid, byte[] encodedPoint)static org.bouncycastle.asn1.x509.SubjectPublicKeyInfocreateSubjectPublicKeyInfo(PublicKey publicKey)static org.bouncycastle.asn1.ASN1ObjectIdentifierdetectCurveOid(ECParameterSpec paramSpec)static KeyPairgenerateDSAKeypair(int plength, int qlength, SecureRandom random)static KeyPairgenerateDSAKeypair(DSAParameterSpec dsaParamSpec, SecureRandom random)static KeyPairgenerateDSAKeypair(org.bouncycastle.crypto.params.DSAParameters dsaParams, SecureRandom random)static DSAPublicKeygenerateDSAPublicKey(DSAPublicKeySpec keySpec)static KeyPairgenerateECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, SecureRandom random)static KeyPairgenerateEdECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, SecureRandom random)static PrivateKeygeneratePrivateKey(org.bouncycastle.asn1.pkcs.PrivateKeyInfo pkInfo)static org.bouncycastle.crypto.params.AsymmetricKeyParametergeneratePrivateKeyParameter(PrivateKey key)static PublicKeygeneratePublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo pkInfo)static org.bouncycastle.crypto.params.AsymmetricKeyParametergeneratePublicKeyParameter(PublicKey key)static KeyPairgenerateRSAKeypair(int keysize, BigInteger publicExponent, SecureRandom random)static RSAPublicKeygenerateRSAPublicKey(RSAPublicKeySpec keySpec)static KeyStoregetInKeyStore(String storeType)static KeyStoregetOutKeyStore(String storeType)static byte[]getUncompressedEncodedECPoint(ECPoint point, int fieldBitSize)static org.bouncycastle.asn1.pkcs.PrivateKeyInfotoPrivateKeyInfo(RSAPrivateCrtKey priv)
-
-
-
Method Detail
-
getInKeyStore
public static KeyStore getInKeyStore(String storeType) throws KeyStoreException
- Throws:
KeyStoreException
-
getOutKeyStore
public static KeyStore getOutKeyStore(String storeType) throws KeyStoreException
- Throws:
KeyStoreException
-
generateRSAKeypair
public static KeyPair generateRSAKeypair(int keysize, BigInteger publicExponent, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
toPrivateKeyInfo
public static org.bouncycastle.asn1.pkcs.PrivateKeyInfo toPrivateKeyInfo(RSAPrivateCrtKey priv) throws IOException
- Throws:
IOException
-
generateDSAKeypair
public static KeyPair generateDSAKeypair(int plength, int qlength, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
generateDSAKeypair
public static KeyPair generateDSAKeypair(org.bouncycastle.crypto.params.DSAParameters dsaParams, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
generateDSAKeypair
public static KeyPair generateDSAKeypair(DSAParameterSpec dsaParamSpec, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
generateDSAPublicKey
public static DSAPublicKey generateDSAPublicKey(DSAPublicKeySpec keySpec) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
generateEdECKeypair
public static KeyPair generateEdECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
generateECKeypair
public static KeyPair generateECKeypair(org.bouncycastle.asn1.ASN1ObjectIdentifier curveId, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException
-
convertXDHToDummyEdDSAPrivateKey
public static PrivateKey convertXDHToDummyEdDSAPrivateKey(PrivateKey key) throws InvalidKeySpecException
Convert XDH edwards private key to EdDSA private key. As the name indicates, the converted key is dummy, you cannot verify the signature signed with the converted private key against the corresponding public key.- Parameters:
key- XDH private key- Returns:
- the corresponding EdDSA private key (dummy)
- Throws:
InvalidKeySpecException- If key is invalid.
-
generatePrivateKey
public static PrivateKey generatePrivateKey(org.bouncycastle.asn1.pkcs.PrivateKeyInfo pkInfo) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
generatePublicKey
public static PublicKey generatePublicKey(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo pkInfo) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
generateRSAPublicKey
public static RSAPublicKey generateRSAPublicKey(RSAPublicKeySpec keySpec) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
generatePrivateKeyParameter
public static org.bouncycastle.crypto.params.AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey key) throws InvalidKeyException
- Throws:
InvalidKeyException
-
generatePublicKeyParameter
public static org.bouncycastle.crypto.params.AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key) throws InvalidKeyException
- Throws:
InvalidKeyException
-
createSubjectPublicKeyInfo
public static org.bouncycastle.asn1.x509.SubjectPublicKeyInfo createSubjectPublicKeyInfo(PublicKey publicKey) throws InvalidKeyException
- Throws:
InvalidKeyException
-
createECPublicKey
public static ECPublicKey createECPublicKey(byte[] encodedAlgorithmIdParameters, byte[] encodedPoint) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
createECPublicKey
public static ECPublicKey createECPublicKey(org.bouncycastle.asn1.ASN1ObjectIdentifier curveOid, byte[] encodedPoint) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
detectCurveOid
public static org.bouncycastle.asn1.ASN1ObjectIdentifier detectCurveOid(ECParameterSpec paramSpec)
-
getUncompressedEncodedECPoint
public static byte[] getUncompressedEncodedECPoint(ECPoint point, int fieldBitSize)
-
-