Enhanced simplified version after Spring encryption tool Security3.1, springsecurity3.1

Source: Internet
Author: User

Enhanced simplified version after Spring encryption tool Security3.1, springsecurity3.1
Enhanced versions increase the number of encrypted strings to 80 bits, and the hash values generated each time are different.

Package com. rapido. utils; import org. springframework. security. crypto. password. passwordEncoder; import org. springframework. security. crypto. password. standardPasswordEncoder;/*** enhanced simplified version after Spring encryption tool Security3.1, iterative 1024 times using a SHA-256 algorithm, using a key (site-wide secret) and 8-bit random salt encryption of the original password * random salt ensures that the hash generated when the same password is used multiple times is different; * The key should be stored separately from the password, you can use one key for encryption to make brute-force cracking more difficult. * Reference: http://www.iteye.com/topic/1120844 ** @ author X-rapido */public class EncryptUtil {private static final String SITE_WIDE_SECRET = "rapido "; // configure the original password private static final PasswordEncoder encoder = new StandardPasswordEncoder (SITE_WIDE_SECRET ); /*** encrypted password ** @ param rawPassword original password * @ return */public static String encrypt (String rawPassword) {return encoder. encode (rawPassword);}/*** password comparison, return the 80-bit encrypted password ** @ param rawPassword original password * @ param password encrypted password * @ return */public static boolean match (String rawPassword, String password) {return encoder. matches (rawPassword, password);} public static void main (String [] args) {String rawPwd = EncryptUtil. encrypt ("rapido"); if (match ("rapido", rawPwd) {System. out. println ("password rapido matched successfully:" + rawPwd + "");} else {System. out. println ("password matching failed");} System. out. println (EncryptUtil. encrypt ("rapido"); System. out. println (EncryptUtil. encrypt ("rapido"); System. out. println (EncryptUtil. encrypt ("rapido "));}}
Output
Password rapido matched successfully: Success



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.