ext/jruby/bcrypt_jruby/BCrypt.javaView |
---|
62 | 62 | * @version 0.2 |
63 | 63 | */ |
64 | 64 | public class BCrypt { |
65 | 65 | |
66 | | - private static int GENSALT_DEFAULT_LOG2_ROUNDS = 10; |
| 66 | + private static final int GENSALT_DEFAULT_LOG2_ROUNDS = 10; |
67 | 67 | private static final int BCRYPT_SALT_LEN = 16; |
68 | 68 | |
69 | 69 | |
70 | 70 | private static final int BLOWFISH_NUM_ROUNDS = 16; |
654 | 654 | StringBuffer rs = new StringBuffer(); |
655 | 655 | |
656 | 656 | if (salt.charAt(0) != '$' || salt.charAt(1) != '2') |
657 | 657 | throw new IllegalArgumentException ("Invalid salt version"); |
658 | | - if (salt.charAt(1) != '$') { |
| 658 | + if (salt.charAt(2) == '$') |
| 659 | + off = 3; |
| 660 | + else { |
659 | 661 | minor = salt.charAt(2); |
660 | 662 | if (minor != 'a' || salt.charAt(3) != '$') |
661 | 663 | throw new IllegalArgumentException ("Invalid salt revision"); |
662 | 664 | off = 4; |
663 | | - } else |
664 | | - off = 3; |
| 665 | + } |
665 | 666 | |
666 | 667 | |
667 | 668 | if (salt.charAt(off + 2) > '$') |
668 | 669 | throw new IllegalArgumentException ("Missing salt rounds"); |
669 | 670 | rounds = Integer.parseInt(salt.substring(off, off + 2)); |
670 | 671 | |
671 | 672 | real_salt = salt.substring(off + 3, off + 25); |
672 | 673 | try { |
673 | | - passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("US-ASCII"); |
| 674 | + passwordb = (password + (minor >= 'a' ? "\000" : "")).getBytes("UTF-8"); |
674 | 675 | } catch (UnsupportedEncodingException uee) { |
675 | | - |
676 | | - throw new AssertionError("US-ASCII is not supported"); |
| 676 | + throw new AssertionError("UTF-8 is not supported"); |
677 | 677 | } |
678 | 678 | |
679 | 679 | saltb = decode_base64(real_salt, BCRYPT_SALT_LEN); |
680 | 680 | |