Class SecurityHelper


  • public final class SecurityHelper
    extends java.lang.Object
    • Method Detail

      • digest

        public static byte[] digest​(SecurityHelper.DigestAlgorithm algo,
                                    java.io.InputStream input)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • digest

        public static byte[] digest​(SecurityHelper.DigestAlgorithm algo,
                                    java.nio.file.Path file)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • digest

        public static byte[] digest​(SecurityHelper.DigestAlgorithm algo,
                                    java.net.URL url)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • genECKeyPair

        public static java.security.KeyPair genECKeyPair​(java.security.SecureRandom random)
      • isValidSign

        public static boolean isValidSign​(byte[] bytes,
                                          byte[] sign,
                                          java.security.interfaces.ECPublicKey publicKey)
                                   throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • isValidSign

        public static boolean isValidSign​(java.io.InputStream input,
                                          byte[] sign,
                                          java.security.interfaces.ECPublicKey publicKey)
                                   throws java.io.IOException,
                                          java.security.SignatureException
        Throws:
        java.io.IOException
        java.security.SignatureException
      • isValidToken

        public static boolean isValidToken​(java.lang.CharSequence token)
      • newCipher

        public static javax.crypto.Cipher newCipher​(java.lang.String algo)
      • newRandom

        public static java.security.SecureRandom newRandom()
      • newECSignSignature

        public static java.security.Signature newECSignSignature​(java.security.interfaces.ECPrivateKey key)
      • newECVerifySignature

        public static java.security.Signature newECVerifySignature​(java.security.interfaces.ECPublicKey key)
      • randomBytes

        public static byte[] randomBytes​(int length)
      • randomBytes

        public static byte[] randomBytes​(java.util.Random random,
                                         int length)
      • randomStringToken

        public static java.lang.String randomStringToken()
      • randomStringToken

        public static java.lang.String randomStringToken​(java.util.Random random)
      • randomToken

        public static byte[] randomToken()
      • randomToken

        public static byte[] randomToken​(java.util.Random random)
      • randomStringAESKey

        public static java.lang.String randomStringAESKey()
      • randomStringAESKey

        public static java.lang.String randomStringAESKey​(java.util.Random random)
      • randomAESKey

        public static byte[] randomAESKey()
      • randomAESKey

        public static byte[] randomAESKey​(java.util.Random random)
      • randomUsername

        public static java.lang.String randomUsername()
      • randomUsername

        public static java.lang.String randomUsername​(java.util.Random random)
      • sign

        public static byte[] sign​(byte[] bytes,
                                  java.security.interfaces.ECPrivateKey privateKey)
      • toHex

        public static java.lang.String toHex​(byte[] bytes)
      • toPublicECKey

        public static java.security.interfaces.ECPublicKey toPublicECKey​(byte[] bytes)
                                                                  throws java.security.spec.InvalidKeySpecException
        Throws:
        java.security.spec.InvalidKeySpecException
      • toPrivateECKey

        public static java.security.interfaces.ECPrivateKey toPrivateECKey​(byte[] bytes)
                                                                    throws java.security.spec.InvalidKeySpecException
        Throws:
        java.security.spec.InvalidKeySpecException
      • verifySign

        public static void verifySign​(byte[] bytes,
                                      byte[] sign,
                                      java.security.interfaces.ECPublicKey publicKey)
                               throws java.security.SignatureException
        Throws:
        java.security.SignatureException
      • verifySign

        public static void verifySign​(java.io.InputStream input,
                                      byte[] sign,
                                      java.security.interfaces.ECPublicKey publicKey)
                               throws java.security.SignatureException,
                                      java.io.IOException
        Throws:
        java.security.SignatureException
        java.io.IOException
      • verifyToken

        public static java.lang.String verifyToken​(java.lang.String token)
      • newECDecryptCipher

        public static javax.crypto.Cipher newECDecryptCipher​(java.security.interfaces.ECPrivateKey privateKey)
      • newECEncryptCipher

        public static javax.crypto.Cipher newECEncryptCipher​(java.security.interfaces.ECPublicKey publicKey)
      • encrypt

        public static byte[] encrypt​(java.lang.String seed,
                                     byte[] cleartext)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encrypt

        public static byte[] encrypt​(java.lang.String seed,
                                     java.lang.String cleartext)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • encrypt

        public static byte[] encrypt​(byte[] raw,
                                     byte[] clear)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • decrypt

        public static byte[] decrypt​(byte[] raw,
                                     byte[] encrypted)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • decrypt

        public static byte[] decrypt​(java.lang.String seed,
                                     byte[] encrypted)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • fromHex

        public static byte[] fromHex​(java.lang.String hexString)