Spring encryption Tool Security3.1 enhanced simplified version

Source: Internet
Author: User

The enhanced version increases the encryption string to 80 bits, and yes, the resulting hash values are not the same.

Package Com.rapido.utils;import Org.springframework.security.crypto.password.passwordencoder;import org.springframework.security.crypto.password.standardpasswordencoder;/** * Spring Encryption tool Enhanced simplified version after Security3.1, using the SHA-256 algorithm, iterative 1024 times, using a key (Site-wide secret) and 8-bit random salt to encrypt the original password * random salt to ensure that the same password used multiple times, the resulting hash is different; The key should be kept separate from the password, use a key when encrypting, make the brute force crack become more difficult * Reference article: http://www.iteye.com/topic/1120844 * * @author X-rapido */public class Enc  Ryptutil {private static final String Site_wide_secret = "Rapido";//original password configuration private static final Passwordencoder encoder = New Standardpasswordencoder (Site_wide_secret);/** * Encrypted password * * @param rawpassword Original password * @return */public static String en Crypt (String Rawpassword) {return encoder.encode (Rawpassword);} /** * Password comparison, return 80-bit encryption 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 match succeeded:" + rawpwd + "");} else {System.out.println ("password match failed");} System.out.println (Encryptutil.encrypt ("Rapido")); System.out.println (Encryptutil.encrypt ("Rapido")); System.out.println (Encryptutil.encrypt ("Rapido"));}}
Output
Password Rapido Match success: Df10352d9f07d49679bd71fc2e7122052572471ffe35f295218f1c41c51aa03eb8071ef339f7a536a190a5bf4f2b34e7b29344108bab B287caf2ddb0e4cb54ade855944707cba3616ead361e3a80b6a74f6ebd5625ba325e8670ed43a14c2f431b3de542912859126701dbfa0deaab9cea8b1 9e285e613fa9a32c7ec25086b99cc018e6a1b9cb937d952019b73d43097c68b6ab9f0eee30351a0a53548b9d758



Spring encryption Tool Security3.1 enhanced simplified version

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.