头像

C# AES加密与慕课的JAVA AES对称加解密代码分享

以下是C#版本代码:

///<summary>

    /// DES加密、解密帮助类

    /// </summary>

    ///

    public class MoocAESEncrypt

    {

        private static char[] BcdLookup = { ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’ };

        

        #region AES加密

        /// <summary>

        /// AES加密

        /// </summary>

        /// <param name=”toEncrypt“>要加密的内容</param>

        /// <param name=”strKey“>密钥(16或者32位)</param>

        /// <returns>Base64转码后的密文</returns>

        public static string Encrypt(string toEncrypt, string strKey)

        {

            byte[] keyArray = HexStrToBytes(strKey);

            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

            RijndaelManaged rDel = new RijndaelManaged();//using System.Security.Cryptography;    

            rDel.Key = keyArray;

            rDel.Mode = CipherMode.ECB;//using System.Security.Cryptography;    

            rDel.Padding = PaddingMode.PKCS7;//using System.Security.Cryptography;                

            ICryptoTransform cTransform = rDel.CreateEncryptor();//using System.Security.Cryptography;    

            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            return BytesToHexStr(resultArray);                                          //返回十六进制数据; 

        }

        #endregion AES加密

        #region AES解密

        /// <summary>

        /// AES解密

        /// </summary>

        /// <param name=”toDecrypt“>要解密的内容</param>

        /// <param name=”strKey“>密钥(16或者32位)</param>

        /// <returns>解密后的明文</returns>

        public static string Decrypt(string toDecrypt, string strKey)

        {

            byte[] keyArray = HexStrToBytes(strKey);

            byte[] toEncryptArray = HexStrToBytes(toDecrypt);                   //16进制to byte[];

            RijndaelManaged rDel = new RijndaelManaged();

            rDel.Key = keyArray;

            rDel.Mode = CipherMode.ECB;

            rDel.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = rDel.CreateDecryptor();

            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            return UTF8Encoding.UTF8.GetString(resultArray);

        }

        #endregion AES解密

        

        #region 转码

        /**

         * 将16进制字符串还原为字节数组.

         */

        public static byte[] HexStrToBytes(string s)

        {

            byte[] bytes;

            bytes = new byte[s.Length / 2];

            for (int i = 0; i < bytes.Length; i++)

            {

                bytes[i] = (byte)Convert.ToInt32(s.Substring(2 * i,2),16);

            }

            return bytes;

        }

        /**

         * 将字节数组转换为16进制字符串的形式.

         */

        public static string BytesToHexStr(byte[] bcd)

        {

            StringBuilder s = new StringBuilder(bcd.Length * 2);

            for (int i = 0; i < bcd.Length; i++)

            {

                s.Append(BcdLookup[(bcd[i] >> 4) & 0x0f]);

                s.Append(BcdLookup[bcd[i] & 0x0f]);

            }

            return s.ToString();

        }

        #endregion

    }

头像

MAMP pro mysql 启动失败

网上有很多关于Mac os 安装MAMP PRO后出现数据库无法启动的故障处理办法,然而每个都试了,完全不能解决问题,错误提示是:

InnoDB: The error means the system cannot find the path specified.

InnoDB: If you are installing InnoDB, remember that you must create

InnoDB: directories yourself, InnoDB does not create them.

InnoDB: Error: could not open single-table tablespace file ./mysql/slave_relay_log_info.ibd

InnoDB: We do not continue the crash recovery, because the table may become

InnoDB: corrupt if we cannot apply the log records in the InnoDB log to it.

InnoDB: To fix the problem and start mysqld:

InnoDB: 1) If there is a permission problem in the file and mysqld cannot

InnoDB: open the file, you should modify the permissions.

InnoDB: 2) If the table is not needed, or you can restore it from a backup,

InnoDB: then you can remove the .ibd file, and InnoDB will do a normal

InnoDB: crash recovery and ignore that table.

InnoDB: 3) If the file system or the disk is broken, and you cannot remove

InnoDB: the .ibd file, you can set innodb_force_recovery > 0 in my.cnf

InnoDB: and force InnoDB to continue crash recovery here.

170324 11:18:41 mysqld_safe mysqld from pid file /Applications/MAMP/tmp/mysql/mysql.pid ended

出现这个情况是之前已经安装过MAMP PRO,从倒数第三行的提示来看需要修改my.cnf,使用mamp打开mysql是可以正常启动的,但是Hosts无法修改路径及配置多个测试域名,每次都要去修改一大堆东西,很不方便,下面我们来解决MAMP PRO mysql无法启动的问题;

其实原因初步判断应该是在MAMP PRO的应用管理端,从应用程序管理文件夹,找到MAMP PRO,显示包内容,完成访问路径/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/my.cnf,复制你对应版本的my.cnf文件到桌面,修改innodb force recovery=2;将原来的备份,替换对应版本的my.cnf,修改完成回到MAMP PRO控制面板,点击mysql,成功启动!

因为我的是多版本,所以打开的是my56.cnf

mamp-sql1
最后来张成功启动的截图,有图有真相

mamp-sql2

作者:cabin_ysl
链接:https://www.jianshu.com/p/4f6644c644ba
来源:简书

头像

Mac 快捷键调整成windows系统一样

Mac OS系统与Windows系统在使用上存在较大差异,尤其在快捷键方面,比如Windows系统中的“复制”快捷键为“ctrl+c”,而在Mac OS系统中则为“command+c”,因此作为习惯了Windows系统的我们,在初次接触Mac OS系统时会觉得有些手足无措。

系统设置-键盘-修饰键

靠近空白键的command换成option,当alt键用

option换成control

control换成command,当ctrl键用

输入法的切换也可以设置成command+空格

这样mac键盘就可以当win键盘用了,pc上怎么耍mac上就怎样耍。

本文转载:https://www.zhihu.com/question/53291792