public class SSecurity
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.security.SecureRandom |
RANDOM
Common secure random number source.
|
Constructor and Description |
---|
SSecurity() |
Modifier and Type | Method and Description |
---|---|
static void |
addStartSSLCertificate(java.security.KeyStore ks,
java.lang.String storepath,
java.lang.String storepass)
Add the startssl.com root certificate to the used store.
|
static void |
addStartSSLToTrustStore(java.lang.String storepass)
Add the start ssl cert to the Java trust store.
|
static java.security.cert.Certificate |
createCertificate(java.io.InputStream in)
Get the textual representation of a certificate.
|
static java.security.cert.Certificate |
createCertificate(java.lang.String text)
Get the textual representation of a certificate.
|
static java.security.cert.Certificate |
generateCertificate(java.security.KeyPair pair,
int days,
java.lang.String algorithm)
Create a self-signed X.509 Certificate
|
static java.security.cert.Certificate |
generateCertificate(java.lang.String dn,
java.security.KeyPair pair,
int days,
java.lang.String algorithm)
Create a self-signed X.509 Certificate
|
static java.security.KeyPair |
generateKeyPair(java.lang.String algorithm,
int keysize)
Create a self-signed X.509 Certificate
|
static java.security.SecureRandom |
generateSecureRandom()
Generates a secure PRNG.
|
static java.lang.String |
getAlgorithm(java.security.cert.Certificate cert)
Get the alogrithm name of a certificate.
|
static java.lang.String |
getCertificateText(java.security.cert.Certificate cert)
Get the textual representation of a certificate.
|
static java.lang.String |
getHexMessageDigest(byte[] data,
java.lang.String type)
Get the digest of a message as a formatted String.
|
static int |
getKeyLength(java.security.Key key)
Get the key length.
|
static java.security.KeyStore |
getKeystore(java.lang.String storepath,
java.lang.String storepass,
java.lang.String keypass,
java.lang.String alias)
Get keystore from a given file.
|
static java.security.SecureRandom |
getSecureRandom()
Gets access to the common secure PRNG.
|
static void |
initKeystore(java.security.KeyStore ks,
java.lang.String storepath,
java.lang.String storepass,
java.lang.String keypass,
java.lang.String alias)
Init keystore with a self-signed certificate.
|
static void |
main(java.lang.String[] args)
Main for testing.
|
static void |
saveKeystore(java.security.KeyStore keystore,
java.lang.String storepath,
java.lang.String storepass)
Get keystore from a given file.
|
static byte[] |
signContent(java.security.PrivateKey key,
java.security.Signature engine,
byte[] content) |
static boolean |
verifyContent(java.security.PublicKey key,
java.security.Signature engine,
byte[] content,
byte[] sig) |
protected static volatile java.security.SecureRandom RANDOM
public static final java.security.SecureRandom getSecureRandom()
public static final java.security.SecureRandom generateSecureRandom()
public static java.security.KeyStore getKeystore(java.lang.String storepath, java.lang.String storepass, java.lang.String keypass, java.lang.String alias)
public static void saveKeystore(java.security.KeyStore keystore, java.lang.String storepath, java.lang.String storepass)
public static void addStartSSLToTrustStore(java.lang.String storepass)
public static void addStartSSLCertificate(java.security.KeyStore ks, java.lang.String storepath, java.lang.String storepass)
public static void initKeystore(java.security.KeyStore ks, java.lang.String storepath, java.lang.String storepass, java.lang.String keypass, java.lang.String alias)
public static java.security.cert.Certificate generateCertificate(java.security.KeyPair pair, int days, java.lang.String algorithm) throws java.security.GeneralSecurityException, java.io.IOException
dn
- the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"pair
- the KeyPairdays
- how many days from now the Certificate is valid foralgorithm
- the signing algorithm, eg "SHA1withRSA"java.security.GeneralSecurityException
java.io.IOException
public static java.security.cert.Certificate generateCertificate(java.lang.String dn, java.security.KeyPair pair, int days, java.lang.String algorithm) throws java.security.GeneralSecurityException, java.io.IOException
dn
- the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"pair
- the KeyPairdays
- how many days from now the Certificate is valid foralgorithm
- the signing algorithm, eg "SHA1withRSA"java.security.GeneralSecurityException
java.io.IOException
public static java.security.KeyPair generateKeyPair(java.lang.String algorithm, int keysize) throws java.security.GeneralSecurityException, java.io.IOException
dn
- the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"pair
- the KeyPairdays
- how many days from now the Certificate is valid foralgorithm
- the signing algorithm, eg "SHA1withRSA"java.security.GeneralSecurityException
java.io.IOException
public static byte[] signContent(java.security.PrivateKey key, java.security.Signature engine, byte[] content) throws java.security.InvalidKeyException, java.security.SignatureException
java.security.InvalidKeyException
java.security.SignatureException
public static boolean verifyContent(java.security.PublicKey key, java.security.Signature engine, byte[] content, byte[] sig) throws java.security.InvalidKeyException, java.security.SignatureException
java.security.InvalidKeyException
java.security.SignatureException
public static java.lang.String getHexMessageDigest(byte[] data, java.lang.String type)
public static int getKeyLength(java.security.Key key)
public static java.lang.String getCertificateText(java.security.cert.Certificate cert)
public static java.security.cert.Certificate createCertificate(java.io.InputStream in)
public static java.security.cert.Certificate createCertificate(java.lang.String text)
public static java.lang.String getAlgorithm(java.security.cert.Certificate cert)
public static void main(java.lang.String[] args)