[Obsessions insomnia night] On the information security management software, user name, password encryption decryption [Annex C # supporting encryption and decryption source] ...

I do not want to do high-tech, in the absence of the ability to do high-tech low-tech'll do a stable, mature, absolutely reliable, and can re-use it, Welcome to the grassroots technology blog

[What is happiness? Every day to do the things they want, family, colleagues, friends, clients, and friends all live in harmony, good health, bulging wallet, a lot of my colleagues around the beautiful feast for the eyes, carefree life is the greatest happiness]

Enough talk, less advertising, direct see the figure

 

1: The user name can not be encrypted, but the password is required to make a single encrypted in an irreversible manner in the company's encryption capabilities, to ensure at least the same level of people can not crack, the effect Figure.

I have a good friend, just to work 3--4 years, the way he works in Hangzhou, very powerful software development level, work is also responsible for the kind of development the company's internal payroll system, when he saw his supervisor pay only after 6000, almost collapsed in despair, because he's in charge of close working 7--8 years, and good ability, he has a monthly salary of 5000, but also want to be higher, but he also knows he's in charge on the 6000 pre-tax, almost collapsed.

A: how could he could get in charge of higher salaries?

B: He is doing better than the director, how many could get it?

C: His future is confused, Hangzhou prices are currently around 20,000, Shashi Hou married his wife to buy a house?

In fact, he did not know the salary of the head of it, possibly motivated and want to do better, better, a vision of the future, but his superiors in order to get back so little, might begin to waver, everything may change , in fact, I fear most people around me than my low salary when working, I am most happy it is that people around than I paid too high, because I have a raise hopes that the future is bright.

   If the software development process management, test engineering, the use of the process, to have a certain degree of data security means, then at least my good friend, nor will the future of despair, in this company may very happy, energetic work a few years, just as we know that the Earth will be destroyed tomorrow, we all have to hang up, there are a few people will take the work? Also dry ass ah right, so the confidentiality of the information system still needs to be strengthened, especially the protection of sensitive data, protection of trade secrets must be done in place, at least awareness of the need to protect our own sin not, but do not seduce others like crime.

 

2: When a user logs on, when you need to save your password, whether it is B / S structure of C / S, the need to have a reversible password.

Let's look at an example B / S system

 

Let us look at an example of supporting the C / S system

 

   Suddenly think of it, nearly 10 years ago, things, then still Ningbo, a Taiwan-funded enterprises, when the company came a year working experienced programmers, the company asked him to write a login program, wrote a full 1 Zhou, finally no way to get abandoned, their arms, and the reason is very simple, do a tried and tested login procedure is not easy, a lot of factors to consider in depth a lot .

 

   Attach supporting irreversible encryption function C # reference.

28171037_SPxU.gif Code
         ///   <summary>
        
///  用户密码加密函数
        
///   </summary>
        
///   <param name="password"> 密码 </param>
        
///   <returns> 加密值 </returns>
         public   static   string  md5( string  password)
        {
            
return  md5(password,  32 );
        }


        
///   <summary>
        
///  加密用户密码
        
///   </summary>
        
///   <param name="password"> 密码 </param>
        
///   <param name="codeLength"> 多少位 </param>
        
///   <returns> 加密密码 </returns>
         public   static   string  md5( string  password,  int  codeLength)
        {
            
if  ( ! string .IsNullOrEmpty(password))
            {
                
//  16位MD5加密(取32位加密的9~25字符)  
                 if  (codeLength  ==   16 )
                {
                    
return  System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password,  " MD5 " ).ToLower().Substring( 8 16 );
                }

                
//  32位加密
                 if  (codeLength  ==   32 )
                {
                    
return  System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password,  " MD5 " ).ToLower();
                }
            }
            
return   string .Empty;
        }

 

 

   再附上配套的,C#可加密解密的函数参考。

28171037_SPxU.gif 代码
     //
    
//  九 字符串加密解密部分
    
//

    
///   <summary>
    
///  DES数据加密
    
///   </summary>
    
///   <param name="targetValue"> 目标字段 </param>
    
///   <returns> 加密 </returns>
     public   static   string  Encrypt( string  targetValue)
    {
        
return  Encrypt(targetValue,  " Project " );
    }

    
///   <summary>
    
///  DES数据加密
    
///   </summary>
    
///   <param name="targetValue"> 目标值 </param>
    
///   <param name="key"> 密钥 </param>
    
///   <returns> 加密值 </returns>
     private   static   string  Encrypt( string  targetValue,  string  key)
    {
        
return  SecretUtil.Encrypt(targetValue, key);
    }


    
///   <summary>
    
///  DES数据解密
    
///   </summary>
    
///   <param name="targetValue"> 目标字段 </param>
    
///   <returns> 解密 </returns>
     public   static   string  Decrypt( string  targetValue)
    {
        
return  Decrypt(targetValue,  " Project " );
    }

    
///   <summary>
    
///  DES数据解密
    
///   </summary>
    
///   <param name="targetValue"></param>
    
///   <param name="key"></param>
    
///   <returns></returns>
     private   static   string  Decrypt( string  targetValue,  string  key)
    {
        
return  SecretUtil.Decrypt(targetValue, key);
    }


        
///   <summary>
        
///  DES数据加密
        
///   </summary>
        
///   <param name="targetValue"> 目标值 </param>
        
///   <param name="key"> 密钥 </param>
        
///   <returns> 加密值 </returns>
         public   static   string  Encrypt( string  targetValue,  string  key)
        {
            
if  ( string .IsNullOrEmpty(targetValue))
            {
                
return   string .Empty;
            }

            var returnValue 
=   new  StringBuilder();
            var des 
=   new  DESCryptoServiceProvider();
            
byte [] inputByteArray  =  Encoding.Default.GetBytes(targetValue);
            
//  通过两次哈希密码设置对称算法的初始化向量   
            des.Key  =  Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile
                                                  (FormsAuthentication.HashPasswordForStoringInConfigFile(key, 
" md5 " ).
                                                       Substring(
0 8 ),  " sha1 " ).Substring( 0 8 ));
            
//  通过两次哈希密码设置算法的机密密钥   
            des.IV  =  Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile
                                                 (FormsAuthentication.HashPasswordForStoringInConfigFile(key, 
" md5 " )
                                                      .Substring(
0 8 ),  " md5 " ).Substring( 0 8 ));
            var ms 
=   new  MemoryStream();
            var cs 
=   new  CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
            cs.Write(inputByteArray, 
0 , inputByteArray.Length);
            cs.FlushFinalBlock();
            
foreach  ( byte  b  in  ms.ToArray())
            {
                returnValue.AppendFormat(
" {0:X2} " , b);
            }
            
return  returnValue.ToString();
        }



        
///   <summary>
        
///  DES数据解密
        
///   </summary>
        
///   <param name="targetValue"></param>
        
///   <param name="key"></param>
        
///   <returns></returns>
         public   static   string  Decrypt( string  targetValue,  string  key)
        {
            
if  ( string .IsNullOrEmpty(targetValue))
            {
                
return   string .Empty;
            }
            
//  定义DES加密对象
            var des  =   new  DESCryptoServiceProvider();   
            
int  len  =  targetValue.Length  /   2 ;
            var inputByteArray 
=   new   byte [len];
            
int  x, i;
            
for  (x  =   0 ; x  <  len; x ++ )
            {
                i 
=  Convert.ToInt32(targetValue.Substring(x  *   2 2 ),  16 );
                inputByteArray[x] 
=  ( byte )i;
            }
            
//  通过两次哈希密码设置对称算法的初始化向量   
            des.Key  =  Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile
                                                  (FormsAuthentication.HashPasswordForStoringInConfigFile(key, 
" md5 " ).
                                                       Substring(
0 8 ),  " sha1 " ).Substring( 0 8 ));
            
//  通过两次哈希密码设置算法的机密密钥   
            des.IV  =  Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile
                                                 (FormsAuthentication.HashPasswordForStoringInConfigFile(key, 
" md5 " )
                                                      .Substring(
0 8 ),  " md5 " ).Substring( 0 8 ));
            
//  定义内存流
            var ms  =   new  MemoryStream();   
            
//  定义加密流
            var cs  =   new  CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);   
            cs.Write(inputByteArray, 
0 , inputByteArray.Length);
            cs.FlushFinalBlock();
            
return  Encoding.Default.GetString(ms.ToArray());
        }

 

 

Link:

Talk about data encryption processing - processing algorithms provide http://www.cnblogs.com/wuhuacong/archive/2010/09/30/1839119.html

 

 

The value of software that can be reused for the people provide a valuable service.

Jiri Gala not only rights management  : when the meaning is not just C # ASP.NET generic rights management, is a holistic concept of development, layered concept, the concept of service-oriented, the basic tools of information technology, to help programmers make money development aid, to help achieve a strong amateur developers have their own set of information management system source code can refer to the accumulation, of course, can be used as a standard entry tutorial C # programming development.

 

 

Reproduced in: https: //my.oschina.net/iwenr/blog/227719

Guess you like

Origin blog.csdn.net/weixin_34290000/article/details/91674284