Package net.schmizz.sshj.common
Class SecurityUtils
java.lang.Object
net.schmizz.sshj.common.SecurityUtils
Static utility method relating to security facilities.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Cipher
static String
getFingerprint
(PublicKey key) Computes the fingerprint for a public key, in the standard SSH format, e.g.static KeyAgreement
getKeyAgreement
(String algorithm) Creates a new instance ofKeyAgreement
with the given algorithm.static KeyFactory
getKeyFactory
(String algorithm) Creates a new instance ofKeyFactory
with the given algorithm.static KeyPairGenerator
getKeyPairGenerator
(String algorithm) Creates a new instance ofKeyPairGenerator
with the given algorithm.static Mac
Create a new instance ofMac
with the given algorithm.static MessageDigest
getMessageDigest
(String algorithm) Create a new instance ofMessageDigest
with the given algorithm.static String
Get the identifier for the registered security provider.static Signature
getSignature
(String algorithm) static boolean
Attempts registering BouncyCastle as security provider if it has not been previously attempted and returns whether the registration succeeded.private static void
register()
static boolean
registerSecurityProvider
(String providerClassName) static void
setRegisterBouncyCastle
(boolean registerBouncyCastle) Configure whether to register the Bouncy Castle Security Provider.static void
setSecurityProvider
(String securityProvider) Specifies the JCE security provider that should be used.
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
BOUNCY_CASTLE
Identifier for the BouncyCastle JCE provider- See Also:
-
SPONGY_CASTLE
Identifier for the BouncyCastle JCE provider- See Also:
-
securityProvider
-
registerBouncyCastle
-
registrationDone
private static boolean registrationDone
-
-
Constructor Details
-
SecurityUtils
public SecurityUtils()
-
-
Method Details
-
registerSecurityProvider
-
getCipher
public static Cipher getCipher(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException -
getFingerprint
Computes the fingerprint for a public key, in the standard SSH format, e.g. "4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21"- Parameters:
key
- the public key- Returns:
- the fingerprint
- See Also:
-
getKeyAgreement
public static KeyAgreement getKeyAgreement(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Creates a new instance ofKeyAgreement
with the given algorithm.- Parameters:
algorithm
- key agreement algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
-
getKeyFactory
public static KeyFactory getKeyFactory(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Creates a new instance ofKeyFactory
with the given algorithm.- Parameters:
algorithm
- key factory algorithm e.g. RSA, DSA- Returns:
- new instance
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
-
getKeyPairGenerator
public static KeyPairGenerator getKeyPairGenerator(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Creates a new instance ofKeyPairGenerator
with the given algorithm.- Parameters:
algorithm
- key pair generator algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
-
getMAC
Create a new instance ofMac
with the given algorithm.- Parameters:
algorithm
- MAC algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
-
getMessageDigest
public static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Create a new instance ofMessageDigest
with the given algorithm.- Parameters:
algorithm
- MessageDigest algorithm name- Returns:
- new instance
- Throws:
NoSuchAlgorithmException
NoSuchProviderException
-
getSecurityProvider
Get the identifier for the registered security provider.- Returns:
- JCE provider identifier
-
getSignature
public static Signature getSignature(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException -
isBouncyCastleRegistered
public static boolean isBouncyCastleRegistered()Attempts registering BouncyCastle as security provider if it has not been previously attempted and returns whether the registration succeeded.- Returns:
- whether BC (or SC on Android) registered
-
setRegisterBouncyCastle
public static void setRegisterBouncyCastle(boolean registerBouncyCastle) Configure whether to register the Bouncy Castle Security Provider. Must be called prior to other methods- Parameters:
registerBouncyCastle
- Enable or disable Bouncy Castle Provider registration on subsequent method invocation
-
setSecurityProvider
Specifies the JCE security provider that should be used.- Parameters:
securityProvider
- identifier for the security provider
-
register
private static void register()
-