zoukankan      html  css  js  c++  java
  • 【加密算法】其它内容

        public enum OutputMethod
        {
            Base64 = 1, //Base64编码
            Hex = 2 //Hex编码
        }
    internal class EadUtil
        {
            public static string Output(byte[] bytes, OutputMethod method = OutputMethod.Base64)
            {
                switch (method)
                {
                    case OutputMethod.Base64:
                        return Base64(bytes);
                    case OutputMethod.Hex:
                        return Hex(bytes);
                    default:
                        return "";
                }
            }
    
            public static byte[] Input(string ciphertext, OutputMethod method = OutputMethod.Base64)
            {
                switch (method)
                {
                    case OutputMethod.Base64:
                        return Base64(ciphertext);
                    case OutputMethod.Hex:
                        return Hex(ciphertext);
                    default:
                        return null;
                }
            }
    
            /// <summary>
            /// 转换为base64位
            /// </summary>
            /// <param name="bytes"></param>
            /// <returns></returns>
            private static string Base64(byte[] bytes)
            {
                return Convert.ToBase64String(bytes);
            }
    
            /// <summary>
            /// 转换为Hex编码
            /// </summary>
            /// <param name="bytes"></param>
            /// <returns></returns>
            private static string Hex(byte[] bytes)
            {
                StringBuilder builder = new StringBuilder();
                foreach (byte num in bytes)
                {
                    builder.AppendFormat("{0:X2}", num);
                }
                return builder.ToString();
            }
    
            private static byte[] Base64(string ciphertext)
            {
                return Convert.FromBase64String(ciphertext);
            }
    
            private static byte[] Hex(string ciphertext)
            {
                byte[] buffer = new byte[ciphertext.Length / 2];
                for (int i = 0; i < (ciphertext.Length / 2); i++)
                {
                    int num2 = Convert.ToInt32(ciphertext.Substring(i * 2, 2), 0x10);
                    buffer[i] = (byte)num2;
                }
    
                return buffer;
            }
        }
  • 相关阅读:
    zabbix api
    pymssql
    ssh别名登录,非常适合从跳板机登录其他主机
    apache httpd 不记录head 的请求。
    mysqldump 参数--single-transaction
    Detect operating system [zabbix]
    mysql 审计server_audit 模块
    Execl矩阵如何转化成Pajek的net文件
    4、keepalived高可用nginx负载均衡
    3、使用keepalived高可用LVS实例演示
  • 原文地址:https://www.cnblogs.com/weiweixiang/p/10102864.html
Copyright © 2011-2022 走看看