zoukankan      html  css  js  c++  java
  • 项目中的常用方法

     public class CommonTools
        {
            private static String EncodeKey="Simon";
            public static Object Copy(Object source, Object item)
            {
                Type t = source.GetType();
                foreach (PropertyInfo property in t.GetProperties())
                {
                    PropertyInfo pro = t.GetProperty(property.Name);
                    if (pro != null && property.PropertyType == pro.PropertyType && pro.CanWrite && property.CanRead)
                    {
                        pro.SetValue(item, property.GetValue(source, null), null);
                    }
                }
                return item;
            }
            public static String Encode(String str)
            {
                String result = String.Empty;
                CspParameters param = new CspParameters();
                param.KeyContainerName =EncodeKey;//密匙容器的名称,保持加密解密一致才能解密成功
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
                {
                    byte[] plaindata = Encoding.Default.GetBytes(str);//将要加密的字符串转换为字节数组
                    byte[] encryptdata = rsa.Encrypt(plaindata, false);//将加密后的字节数据转换为新的加密字节数组
                    result = Convert.ToBase64String(encryptdata);//将加密后的字节数组转换为字符串
                }
                return result;
            }
            public static String Decode(String str)
            {
                String result = String.Empty;
                CspParameters param = new CspParameters();
                param.KeyContainerName = EncodeKey;
                using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
                {
                    byte[] encryptdata = Convert.FromBase64String(str);
                    byte[] decryptdata = rsa.Decrypt(encryptdata, false);
                    result = Encoding.Default.GetString(decryptdata);
                }
                return result;
            }
        }

  • 相关阅读:
    Vue开发之vue-router的基本使用
    react监听URL的正确方式
    Electron Windows增加托盘悬浮框功能
    vue自定义标签和单页面多路由实现
    如何通过带有Vue插槽的组件传递HTML内容
    Flutter使用JsBridge方式处理Webview与H5通信
    npm实用知识_命令合集
    <keep-alive> 缓存及其缓存优化原理
    深入学习和理解 Redux
    Centos7使用Yum安装高版本的LNMP
  • 原文地址:https://www.cnblogs.com/zhangsongshan/p/3056142.html
Copyright © 2011-2022 走看看