分享几种有趣的加密方式和几个在线加解密网址
Posted 微瑟秋风
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分享几种有趣的加密方式和几个在线加解密网址相关的知识,希望对你有一定的参考价值。
目录
一、有趣的加密方式
1.1、当铺密码
这种加密算法相当简单:当前汉字有多少笔画出头,就是转化成数字几。
王:该字外面有 6 个出头的位置,所以该汉字对应的数字就是 6;
口:该字外面没有出头的位置,那就是0;
人:该字外面有 3 个出头的位置,所以该汉字对应的数字就是 3;
下面是一段由当铺密码组成的字符:
密文:王夫 井工 夫口 由中人 井中 夫夫 由中大
对应: 67 84 70 123 82 77 125
1.2、猪圈密码
由点和线组成的形状即代表在该形状内的那个字↓↓↓↓
由此可以得到密码表↓↓↓↓
例如:the weather is sunny
加密后就得到了
1.3、键盘密码
电脑键盘上多个字符表示一个字母,例如9IKLP0代表字母O。
如图,9IKLP0字符围绕中间的字符是O。
二、在线加解密网址
2.1、在线AES、DES加解密
https://www.sojson.com/encrypt_aes.html
https://www.sojson.com/encrypt_des.html
2.2、与佛论禅在线加解密
https://www.keyfc.net/bbs/tools/tudoucode.aspx
2.3、核心价值观在线编码
https://sym233.github.io/core-values-encoder
2.4、猪圈密码在线加解密
https://www.xiao84.com/tools/103177.html
基础分享C#封装的几个加解密类
前段时间一个业余项目涉及到字符串和文件的加密,所以写了封装了几个给予DES,AES,MD5的加密解密类.
直接看代码
DesSecurity.cs
/// <summary> /// 基于DES加密解密 /// </summary> public static class DesSecurity { public static byte[] Encrypt( byte[] data ,string key , bool ispaddingzeros = true, bool isEcbMode = true ) { byte[] result; using (DESCryptoServiceProvider des = new DESCryptoServiceProvider { Key = Encoding.Default.GetBytes(key), IV = Encoding.Default.GetBytes("visonsec"), Mode = isEcbMode ? CipherMode.ECB : CipherMode.CBC, Padding = ispaddingzeros ? PaddingMode.Zeros : PaddingMode.None }) { byte[] array; using(MemoryStream ms = new MemoryStream()) { using(CryptoStream cryptoStream = new CryptoStream( ms , des.CreateEncryptor(), CryptoStreamMode.Write)) { cryptoStream.Write(data, 0, data.Length); cryptoStream.FlushFinalBlock(); } array = ms.ToArray(); } result = array; } return result; } public static string Encrypt( string data, string key ) { byte[] bytes = Encoding.Default.GetBytes(data); byte[] valuetocon = DesSecurity.Encrypt(bytes , key, true ,true ); return StringConverter.ToHexString(valuetocon); } public static byte[] Descrypt( byte[] data ,string key , bool ispaddingzeros = true , bool isecbmode = true ) { byte[] result; using(DESCryptoServiceProvider des = new DESCryptoServiceProvider{ Key = Encoding.Default.GetBytes(key), IV = Encoding.Default.GetBytes("visonsec"), Mode= isecbmode ? CipherMode.ECB : CipherMode.CBC , Padding = ispaddingzeros ? PaddingMode.Zeros:PaddingMode.None }) { byte[] array; using (MemoryStream ms = new MemoryStream()) { using( CryptoStream cs = new CryptoStream( ms , des.CreateDecryptor(), CryptoStreamMode.Write)) { cs.Write(data, 0, data.Length); cs.FlushFinalBlock(); } array = ms.ToArray(); } result = array; } return result; } public static string Descrypt(string data , string key ) { byte[] datas = StringConverter.ToHexBytes(data); byte[] bytes = DesSecurity.Descrypt(datas, key, true, true); return Encoding.Default.GetString(bytes).Replace("\0", null); } }
AESSecurity.cs
public static class AESSecurity { public static byte[] Encrypt(byte[] data, string key) { Rijndael rijndael = Rijndael.Create(); rijndael.Mode = CipherMode.ECB; rijndael.Padding = PaddingMode.PKCS7; rijndael.Key = Encoding.UTF8.GetBytes(key); byte[] result; try { using(MemoryStream ms = new MemoryStream()) { using(CryptoStream cs = new CryptoStream(ms,rijndael.CreateEncryptor(), CryptoStreamMode.Write)) { cs.Write(data, 0, data.Length); cs.FlushFinalBlock(); result = ms.ToArray(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("AES EXCEPTION:" + ex.Message); result = null; } finally { rijndael.Clear(); } return result; } public static byte[] Encrypt(string data, string key) { return AESSecurity.Encrypt(Encoding.UTF8.GetBytes(data), key); } public static byte[] Descrypt(byte[] data ,string key ) { Rijndael rijndael = Rijndael.Create(); rijndael.Mode = CipherMode.ECB; rijndael.Padding = PaddingMode.PKCS7; rijndael.Key = Encoding.UTF8.GetBytes(key); byte[] result; try { using(MemoryStream ms = new MemoryStream()) { using(CryptoStream cs = new CryptoStream(ms, rijndael.CreateDecryptor() , CryptoStreamMode.Write)) { cs.Write(data, 0, data.Length); cs.FlushFinalBlock(); result = ms.ToArray(); } } } catch (Exception e) { result = null; System.Diagnostics.Debug.WriteLine(e.Message); } finally { rijndael.Clear(); } return result; } }
MD5Security.cs
byte[] buf = StringConverter.ToBytes(value); string result; using(MD5CryptoServiceProvider md = new MD5CryptoServiceProvider()) { byte[] v = md.ComputeHash(buf); string s = BitConverter.ToString(v, 4, 8).Replace("-", string.Empty); result = s; } return result; } public static string Encrypt32( string value ) { if (value == null) throw new ArgumentNullException("value"); byte[] buf = StringConverter.ToBytes(value); string result = null; using(MD5CryptoServiceProvider md = new MD5CryptoServiceProvider()) { byte[] array = md.ComputeHash(buf); StringBuilder sb = new StringBuilder(); for(int i = 0 ; i < array.Length ; i++ ) { sb.Append(array[i].ToString("x2")); } result = sb.ToString(); } return result; } public static string GetMD5FromFile( string file ) { if(File.Exists(file)) { string result; using(FileStream fs = new FileStream(file,FileMode.Open)) { using(MD5CryptoServiceProvider md = new MD5CryptoServiceProvider()) { byte[] array = md.ComputeHash(fs); StringBuilder sb = new StringBuilder(); for( int i = 0 ; i < array.Length ; i++ ) { sb.Append(array[i].ToString("x2")); } result = sb.ToString(); } } return result; } else { return null; } } }
StringConverter.cs 字符串转换辅助类
[System.Flags] public enum StringEncodeType { EN_Default = 0 , EN_UTF8 = 1 , EN_UnicodeEncoding = 2 , EN_Base64 = 3 } public static class StringConverter { public static string ToHexString(byte[] valueToConvert) { if (valueToConvert == null) { throw new ArgumentNullException(); } string text = string.Empty; for (int i = 0; i < valueToConvert.Length; i++) { text += valueToConvert[i].ToString("X2"); } return text; } public static byte[] ToHexBytes(string valueToConvert) { if (valueToConvert == null) { throw new ArgumentNullException("valueToConvert"); } valueToConvert = valueToConvert.Replace(" ", string.Empty); if (valueToConvert.Length % 2 != 0) { throw new FormatException("valueToConvert"); } byte[] array = new byte[valueToConvert.Length / 2]; for (int i = 0; i < array.Length; i++) { array[i] = Convert.ToByte(valueToConvert.Substring(i * 2, 2), 16); } return array; } public static byte[] ToBytes(string valueToConvert, StringEncodeType stringEncodingType) { if (valueToConvert == null) { throw new ArgumentNullException("valueToConvert"); } byte[] result = null; switch (stringEncodingType) { case StringEncodeType.EN_Default: result = Encoding.Default.GetBytes(valueToConvert); break; case StringEncodeType.EN_UTF8: result = Encoding.UTF8.GetBytes(valueToConvert); break; case StringEncodeType.EN_UnicodeEncoding: result = new UnicodeEncoding().GetBytes(valueToConvert); break; case StringEncodeType.EN_Base64: result = Convert.FromBase64String(valueToConvert); break; } return result; } public static byte[] ToBytes(string valueToConvert) { return StringConverter.ToBytes(valueToConvert, StringEncodeType.EN_UTF8); } }
--------
end
以上是关于分享几种有趣的加密方式和几个在线加解密网址的主要内容,如果未能解决你的问题,请参考以下文章