码迷,mamicode.com
首页 > 其他好文 > 详细

加盐密码哈希:如何正确使用

时间:2014-12-25 12:50:31      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

一篇很棒的文章。

http://blog.jobbole.co

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Salt
{
    public static class RNG
    {
        private static RNGCryptoServiceProvider rngp = new RNGCryptoServiceProvider();
        private static byte[] rb = new byte[4];

        /// <summary>
        /// 产生一个非负数的随机数
        /// </summary>
        public static int Next()
        {
            rngp.GetBytes(rb);
            int value = BitConverter.ToInt32(rb, 0);
            if (value < 0) value = -value;
            return value;
        }
        /// <summary>
        /// 产生一个非负数且最大值 max 以下的随机数
        /// </summary>
        /// <param name="max">最大值</param>
        public static int Next(int max)
        {
            rngp.GetBytes(rb);
            int value = BitConverter.ToInt32(rb, 0);
            value = value % (max + 1);
            if (value < 0) value = -value;
            return value;
        }
        /// <summary>
        /// 产生一个非负数且最小值在 min 以上最大值在 max 以下的随机数
        /// </summary>
        /// <param name="min">最小值</param>
        /// <param name="max">最大值</param>
        public static int Next(int min, int max)
        {
            int value = Next(max - min) + min;
            return value;
        }
    }
}

 

m/61872/

加盐密码哈希:如何正确使用

标签:

原文地址:http://www.cnblogs.com/seakwan/p/4184231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!