ASP.NET.Identity Encryption algorithm

Source: Internet
Author: User

Tag:blog    algorithm    for   io   .net    new   

        public static string Hashpassword (string password) {if (password = = null) {            throw new ArgumentNullException ("password");            } byte[] Salt;            byte[] bytes; using (rfc2898derivebytes rfc2898derivebytes = new Rfc2898derivebytes (password, +,)) {sal                t = Rfc2898derivebytes.salt;            bytes = Rfc2898derivebytes.getbytes (32);            } byte[] array = new byte[49];            Buffer.blockcopy (salt, 0, array, 1, 16);            Buffer.blockcopy (bytes, 0, array, 17, 32);        return convert.tobase64string (array); public static bool Verifyhashedpassword (string Hashedpassword, string password) {if (Hashedpas            Sword = = null) {return false;            } if (password = = null) {throw new ArgumentNullException ("password"); } byte[] ArRay = convert.frombase64string (Hashedpassword); if (array. Length! = 49 | |            ARRAY[0]! = 0) {return false;            } byte[] Array2 = new BYTE[16];            Buffer.blockcopy (array, 1, array2, 0, 16);            byte[] Array3 = new BYTE[32];            Buffer.blockcopy (array, n, array3, 0, 32);            byte[] bytes;                using (rfc2898derivebytes rfc2898derivebytes = new Rfc2898derivebytes (password, array2, 1000)) {            bytes = Rfc2898derivebytes.getbytes (32);        } return bytearraysequal (Array3, bytes); } private static bool Bytearraysequal (byte[] A, byte[] b) {if (object.            ReferenceEquals (A, B)) {return true;            if (a = = NULL | | b = NULL | | A.length! = b.length) {return false;            } bool flag = TRUE;   for (int i = 0; i < a.length; i++) {             Flag &= (A[i] = = B[i]);        } return flag;  }

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.