Package net.schmizz.sshj.common
Class SecurityUtils
- java.lang.Object
-
- net.schmizz.sshj.common.SecurityUtils
-
public class SecurityUtils extends java.lang.ObjectStatic utility method relating to security facilities.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBOUNCY_CASTLEIdentifier for the BouncyCastle JCE providerstatic java.lang.StringSPONGY_CASTLEIdentifier for the BouncyCastle JCE provider
-
Constructor Summary
Constructors Constructor Description SecurityUtils()
-
Method Summary
Modifier and Type Method Description static javax.crypto.CiphergetCipher(java.lang.String transformation)static java.lang.StringgetFingerprint(java.security.PublicKey key)Computes the fingerprint for a public key, in the standard SSH format, e.g.static javax.crypto.KeyAgreementgetKeyAgreement(java.lang.String algorithm)Creates a new instance ofKeyAgreementwith the given algorithm.static java.security.KeyFactorygetKeyFactory(java.lang.String algorithm)Creates a new instance ofKeyFactorywith the given algorithm.static java.security.KeyPairGeneratorgetKeyPairGenerator(java.lang.String algorithm)Creates a new instance ofKeyPairGeneratorwith the given algorithm.static javax.crypto.MacgetMAC(java.lang.String algorithm)Create a new instance ofMacwith the given algorithm.static java.security.MessageDigestgetMessageDigest(java.lang.String algorithm)Create a new instance ofMessageDigestwith the given algorithm.static java.lang.StringgetSecurityProvider()Get the identifier for the registered security provider.static java.security.SignaturegetSignature(java.lang.String algorithm)static booleanisBouncyCastleRegistered()Attempts registering BouncyCastle as security provider if it has not been previously attempted and returns whether the registration succeeded.static booleanregisterSecurityProvider(java.lang.String providerClassName)static voidsetRegisterBouncyCastle(boolean registerBouncyCastle)static voidsetSecurityProvider(java.lang.String securityProvider)Specifies the JCE security provider that should be used.
-
-
-
Field Detail
-
BOUNCY_CASTLE
public static final java.lang.String BOUNCY_CASTLE
Identifier for the BouncyCastle JCE provider- See Also:
- Constant Field Values
-
SPONGY_CASTLE
public static final java.lang.String SPONGY_CASTLE
Identifier for the BouncyCastle JCE provider- See Also:
- Constant Field Values
-
-
Method Detail
-
registerSecurityProvider
public static boolean registerSecurityProvider(java.lang.String providerClassName)
-
getCipher
public static javax.crypto.Cipher getCipher(java.lang.String transformation) throws java.security.NoSuchAlgorithmException, javax.crypto.NoSuchPaddingException, java.security.NoSuchProviderException- Throws:
java.security.NoSuchAlgorithmExceptionjavax.crypto.NoSuchPaddingExceptionjava.security.NoSuchProviderException
-
getFingerprint
public static java.lang.String getFingerprint(java.security.PublicKey key)
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:
- specification
-
getKeyAgreement
public static javax.crypto.KeyAgreement getKeyAgreement(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreates a new instance ofKeyAgreementwith the given algorithm.- Parameters:
algorithm- key agreement algorithm- Returns:
- new instance
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderException
-
getKeyFactory
public static java.security.KeyFactory getKeyFactory(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreates a new instance ofKeyFactorywith the given algorithm.- Parameters:
algorithm- key factory algorithm e.g. RSA, DSA- Returns:
- new instance
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderException
-
getKeyPairGenerator
public static java.security.KeyPairGenerator getKeyPairGenerator(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreates a new instance ofKeyPairGeneratorwith the given algorithm.- Parameters:
algorithm- key pair generator algorithm- Returns:
- new instance
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderException
-
getMAC
public static javax.crypto.Mac getMAC(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreate a new instance ofMacwith the given algorithm.- Parameters:
algorithm- MAC algorithm- Returns:
- new instance
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderException
-
getMessageDigest
public static java.security.MessageDigest getMessageDigest(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderExceptionCreate a new instance ofMessageDigestwith the given algorithm.- Parameters:
algorithm- MessageDigest algorithm name- Returns:
- new instance
- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.NoSuchProviderException
-
getSecurityProvider
public static java.lang.String getSecurityProvider()
Get the identifier for the registered security provider.- Returns:
- JCE provider identifier
-
getSignature
public static java.security.Signature getSignature(java.lang.String algorithm) throws java.security.NoSuchAlgorithmException, java.security.NoSuchProviderException- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.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)
-
setSecurityProvider
public static void setSecurityProvider(java.lang.String securityProvider)
Specifies the JCE security provider that should be used.- Parameters:
securityProvider- identifier for the security provider
-
-