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 Cipherstatic StringgetFingerprint(PublicKey key) Computes the fingerprint for a public key, in the standard SSH format, e.g.static KeyAgreementgetKeyAgreement(String algorithm) Creates a new instance ofKeyAgreementwith the given algorithm.static KeyFactorygetKeyFactory(String algorithm) Creates a new instance ofKeyFactorywith the given algorithm.static KeyPairGeneratorgetKeyPairGenerator(String algorithm) Creates a new instance ofKeyPairGeneratorwith the given algorithm.static MacCreate a new instance ofMacwith the given algorithm.static MessageDigestgetMessageDigest(String algorithm) Create a new instance ofMessageDigestwith the given algorithm.static StringGet the identifier for the registered security provider.static SignaturegetSignature(String algorithm) static booleanAttempts registering BouncyCastle as security provider if it has not been previously attempted and returns whether the registration succeeded.private static voidregister()static booleanregisterSecurityProvider(String providerClassName) static voidsetRegisterBouncyCastle(boolean registerBouncyCastle) Configure whether to register the Bouncy Castle Security Provider.static voidsetSecurityProvider(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 ofKeyAgreementwith the given algorithm.- Parameters:
algorithm- key agreement algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderException
-
getKeyFactory
public static KeyFactory getKeyFactory(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Creates a new instance ofKeyFactorywith the given algorithm.- Parameters:
algorithm- key factory algorithm e.g. RSA, DSA- Returns:
- new instance
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderException
-
getKeyPairGenerator
public static KeyPairGenerator getKeyPairGenerator(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Creates a new instance ofKeyPairGeneratorwith the given algorithm.- Parameters:
algorithm- key pair generator algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderException
-
getMAC
Create a new instance ofMacwith the given algorithm.- Parameters:
algorithm- MAC algorithm- Returns:
- new instance
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderException
-
getMessageDigest
public static MessageDigest getMessageDigest(String algorithm) throws NoSuchAlgorithmException, NoSuchProviderException Create a new instance ofMessageDigestwith the given algorithm.- Parameters:
algorithm- MessageDigest algorithm name- Returns:
- new instance
- Throws:
NoSuchAlgorithmExceptionNoSuchProviderException
-
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()
-