类 BCryptUtil


  • public class BCryptUtil
    extends Object
    加密工具
    作者:
    zhanglinfeng
    • 构造器详细资料

      • BCryptUtil

        public BCryptUtil()
    • 方法详细资料

      • hashpw

        public static String hashpw​(String password,
                                    String salt)
        Hash a password using the OpenBSD bcrypt scheme
        参数:
        password - the password to hash
        salt - the salt to hash with (perhaps generated using BCrypt.gensalt)
        返回:
        the hashed password
      • hashpw

        public static String hashpw​(byte[] passwordb,
                                    String salt)
        Hash a password using the OpenBSD bcrypt scheme
        参数:
        passwordb - the password to hash, as a byte array
        salt - the salt to hash with (perhaps generated using BCrypt.gensalt)
        返回:
        the hashed password
      • gensalt

        public static String gensalt​(String prefix,
                                     int log_rounds,
                                     SecureRandom random)
                              throws IllegalArgumentException
        Generate a salt for use with the BCrypt.hashpw() method
        参数:
        prefix - the prefix value (default $2a)
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        random - an instance of SecureRandom to use
        返回:
        an encoded salt value
        抛出:
        IllegalArgumentException - if prefix or log_rounds is invalid
      • gensalt

        public static String gensalt​(String prefix,
                                     int log_rounds)
                              throws IllegalArgumentException
        Generate a salt for use with the BCrypt.hashpw() method
        参数:
        prefix - the prefix value (default $2a)
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        返回:
        an encoded salt value
        抛出:
        IllegalArgumentException - if prefix or log_rounds is invalid
      • gensalt

        public static String gensalt​(int log_rounds,
                                     SecureRandom random)
                              throws IllegalArgumentException
        Generate a salt for use with the BCrypt.hashpw() method
        参数:
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        random - an instance of SecureRandom to use
        返回:
        an encoded salt value
        抛出:
        IllegalArgumentException - if log_rounds is invalid
      • gensalt

        public static String gensalt​(int log_rounds)
                              throws IllegalArgumentException
        Generate a salt for use with the BCrypt.hashpw() method
        参数:
        log_rounds - the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2**log_rounds.
        返回:
        an encoded salt value
        抛出:
        IllegalArgumentException - if log_rounds is invalid
      • gensalt

        public static String gensalt()
        Generate a salt for use with the BCrypt.hashpw() method, selecting a reasonable default for the number of hashing rounds to apply
        返回:
        an encoded salt value
      • checkpw

        public static boolean checkpw​(String plaintext,
                                      String hashed)
        Check that a plaintext password matches a previously hashed one
        参数:
        plaintext - the plaintext password to verify
        hashed - the previously-hashed password
        返回:
        true if the passwords match, false otherwise
      • checkpw

        public static boolean checkpw​(byte[] passwordb,
                                      String hashed)
        Check that a password (as a byte array) matches a previously hashed one
        参数:
        passwordb - the password to verify, as a byte array
        hashed - the previously-hashed password
        返回:
        true if the passwords match, false otherwise
        从以下版本开始:
        5.3