|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
//------------------------------------------------------------------------------ // <copyright file="CryptoUtil.cs" company="Microsoft"> // Copyright (c) Microsoft Corporation. All rights reserved. // </copyright> //------------------------------------------------------------------------------ namespace System.Web.Security.Cryptography { using System; using System.Runtime.CompilerServices; using System.Security.Cryptography; using System.Text; using System.Web.Util; // Contains helper methods for dealing with cryptographic operations. internal static class CryptoUtil { /// <summary> /// Similar to Encoding.UTF8, but throws on invalid bytes. Useful for security routines where we need /// strong guarantees that we're always producing valid UTF8 streams. /// </summary> public static readonly UTF8Encoding SecureUTF8Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); /// <summary> /// Converts a byte array into its hexadecimal representation. /// </summary> /// <param name="data">The binary byte array.</param> /// <returns>The hexadecimal (uppercase) equivalent of the byte array.</returns> public static string BinaryToHex(byte[] data) { if (data == null) { return null; } char[] hex = new char[checked(data.Length * 2)]; for (int i = 0; i < data.Length; i++) { byte thisByte = data[i]; hex[2 * i] = NibbleToHex((byte)(thisByte >> 4)); // high nibble hex[2 * i + 1] = NibbleToHex((byte)(thisByte & 0xf)); // low nibble } return new string(hex); } // Determines if two buffer instances are equal, e.g. whether they contain the same payload. This method // is written in such a manner that it should take the same amount of time to execute regardless of // whether the result is success or failure. The modulus operation is intended to make the check take the // same amount of time, even if the buffers are of different lengths. // // !! DO NOT CHANGE THIS METHOD WITHOUT SECURITY [MethodImpl(MethodImplOptions.NoOptimization)] public static bool BuffersAreEqual(byte[] buffer1, int buffer1Offset, int buffer1Count, byte[] buffer2, int buffer2Offset, int buffer2Count) { Debug.ValidateArrayBounds(buffer1, buffer1Offset, buffer1Count); Debug.ValidateArrayBounds(buffer2, buffer2Offset, buffer2Count); bool success = (buffer1Count == buffer2Count); // can't possibly be successful if the buffers are of different lengths for (int i = 0; i < buffer1Count; i++) { success &= (buffer1[buffer1Offset + i] == buffer2[buffer2Offset + (i % buffer2Count)]); } return success; } /// <summary> /// Computes the SHA256 hash of a given input. /// </summary> /// <param name="input">The input over which to compute the hash.</param> /// <returns>The binary hash (32 bytes) of the input.</returns> public static byte[] ComputeSHA256Hash(byte[] input) { return ComputeSHA256Hash(input, 0, input.Length); } /// <summary> /// Computes the SHA256 hash of a given segment in a buffer. /// </summary> /// <param name="buffer">The buffer over which to compute the hash.</param> /// <param name="offset">The offset at which to begin computing the hash.</param> /// <param name="count">The number of bytes in the buffer to include in the hash.</param> /// <returns>The binary hash (32 bytes) of the buffer segment.</returns> public static byte[] ComputeSHA256Hash(byte[] buffer, int offset, int count) { Debug.ValidateArrayBounds(buffer, offset, count); using (SHA256 sha256 = CryptoAlgorithms.CreateSHA256()) { return sha256.ComputeHash(buffer, offset, count); } } /// <summary> /// Returns an IV that's based solely on the contents of a buffer; useful for generating /// predictable IVs for ciphertexts that need to be cached. The output value is only /// appropriate for use as an IV and must not be used for any other purpose. /// </summary> /// <remarks>This method uses an iterated unkeyed SHA256 to calculate the IV.</remarks> /// <param name="buffer">The input buffer over which to calculate the IV.</param> /// <param name="ivBitLength">The requested length (in bits) of the IV to generate.</param> /// <returns>The calculated IV.</returns> public static byte[] CreatePredictableIV(byte[] buffer, int ivBitLength) { // Algorithm: // T_0 = SHA256(buffer) // T_n = SHA256(T_{n-1}) // output = T_0 || T_1 || ... || T_n (as many blocks as necessary to reach ivBitLength) byte[] output = new byte[ivBitLength / 8]; int bytesCopied = 0; int bytesRemaining = output.Length; using (SHA256 sha256 = CryptoAlgorithms.CreateSHA256()) { while (bytesRemaining > 0) { byte[] hashed = sha256.ComputeHash(buffer); int bytesToCopy = Math.Min(bytesRemaining, hashed.Length); Buffer.BlockCopy(hashed, 0, output, bytesCopied, bytesToCopy); bytesCopied += bytesToCopy; bytesRemaining -= bytesToCopy; buffer = hashed; // next iteration (if it occurs) will operate over the block just hashed } } return output; } /// <summary> /// Converts a hexadecimal string into its binary representation. /// </summary> /// <param name="data">The hex string.</param> /// <returns>The byte array corresponding to the contents of the hex string, /// or null if the input string is not a valid hex string.</returns> public static byte[] HexToBinary(string data) { if (data == null || data.Length % 2 != 0) { // input string length is not evenly divisible by 2 return null; } byte[] binary = new byte[data.Length / 2]; for (int i = 0; i < binary.Length; i++) { int highNibble = HttpEncoderUtility.HexToInt(data[2 * i]); int lowNibble = HttpEncoderUtility.HexToInt(data[2 * i + 1]); if (highNibble == -1 || lowNibble == -1) { return null; // bad hex data } binary[i] = (byte)((highNibble << 4) | lowNibble); } return binary; } // converts a nibble (4 bits) to its uppercase hexadecimal character representation [0-9, A-F] private static char NibbleToHex(byte nibble) { return (char)((nibble < 10) ? (nibble + '0') : (nibble - 10 + 'A')); } } } |
我在开发测试过程中,发现使用wx.onMenuShareTimeline无效果,没有显示我定义的图片、title和链接,经过调试发现原因如下: 1.图片大小要大于300pix才能显示 2.这个方法必须先config成功,然后再wx.ready里才能调用。我直接放到$(function(){})里执行,实践证明是不行的。
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
wx.config({ debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '{$appid}', // 必填,公众号的唯一标识 timestamp: "{$signPackage.timestamp}", // 必填,生成签名的时间戳 nonceStr: '{$signPackage.nonceStr}', // 必填,生成签名的随机串 signature: '{$signPackage.signature}',// 必填,签名,见附录1 jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function () { wx.onMenuShareTimeline({ title: '--{$info.name}', // 分享标题 link: '{$url}__URL__/index?pid={$pid}&puid={$uid}', // 分享链接,将当前登录用户转为puid,以便于发展下线 imgUrl: '{$url}__PUBLIC__/Uploads/{$goodsvo.image}', // 分享图标 success: function () { // 用户确认分享后执行的回调函数 alert('分享成功'); }, cancel: function () { // 用户取消分享后执行的回调函数 } }); wx.error(function (res) { // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。 alert("errorMSG:" + res); }); }); |
from:http://www.cnblogs.com/zhouyu629/p/4496065.html
View DetailsWIN2003的服务器,打开系统自带的防火墙后,用FLASHFXP连接FTP时出现沟通困难,无法列表数据,FTP无法连接,通过检查后发现WIN2003在默认情况下,该防火墙是禁止开放本机FTP服务的。通过一系列的试验发现解决该问题的方法,希望对大家有所帮助,步骤如下所述: 第1步,点击开始菜单,进入控制面板,选择WINDOW防火墙,进入防火墙设置窗口,选择例外菜单,进入防火墙例外窗口,之后点击下方的添加端口,出现添加端口对话框,在此设置名称FTP,和开启端口21后,点击确定,如图1所示: 图1防火墙例外中添加端口设置 第2步,在桌面上右键单击“网上邻居”图标,选择“属性”命令。在打开的“网络连接”窗口中右键单击“本地连接”图标,选择“属性”命令,之后选择高级按钮,点击设置进入WINDOW防火墙设置窗口,如图2所示: 图2本地连接属性进入防火墙设置 第3步,打开“防火墙设置”对话框,切换到“高级”选项卡。单击本地连接对话框右侧的“设置”按钮,打开“高级设置”对话框。 图3本地连接高级设置窗口 第4步,在默认的“服务”选项卡中,用户可以设置在开启防火墙功能的前提下本机开放的服务类别。由于需要提供FTP服务,因此只需开放该服务即可。在服务列表中选中“FTP服务器”选项,随之打开的“服务设置”对话框要求填写计算机名称。保持默认内容并连续单击“确定”完成设置即可,如图4所示。 from:http://blog.pynet.net/u/pyxyp/archives/2011/99.html
View Details通过openssl工具生成RSA的公钥和私钥(opnssl工具可在互联网中下载到,也可以点此下载无线接口包,里面包含此工具) 打开openssl文件夹下的bin文件夹,执行openssl.exe文件: 1)生成RSA私钥 输入“生成命令.txt”文件中:“genrsa -out rsa_private_key.pem 1024”,并回车得到生成成功的结果,如下图: 此时,我们可以在bin文件夹中看到一个文件名为rsa_private_key.pem的文件,用记事本方式打开它,可以看到—--BEGIN RSA PRIVATE KEY—--开头,—--END RSA PRIVATE KEY—--结尾的没有换行的字符串,这个就是原始的私钥。 2)把RSA私钥转换成PKCS8格式 输入命令:pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt,并回车当前界面中会直接显示出生成结果,这个结果就是PKCS8格式的私钥,如下图: 右键点击openssl窗口上边边缘,选择编辑→标记,选中要复制的文字(如上图), 此时继续右键点击openssl窗口上边边缘,选择编辑→复制, 把复制的内容粘土进一个新的记事本中,可随便命名,只要知道这个是PKCS8格式的私钥即可。 3)生成RSA公钥 输入命令:rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem,并回车,得到生成成功的结果,如下图: 此时,我们可以在bin文件夹中看到一个文件名为rsa_public_key.pem的文件,用记事本方式打开它,可以看到—--BEGIN PUBLIC KEY—--开头,—--END PUBLIC KEY—--结尾的没有换行的字符串,这个就是公钥。 详情见开放平台对于密钥生成说明 注意:请妥善保管好生成的公私钥! 附:点此查看如何上传公钥 from:https://cshall.alipay.com/enterprise/help_detail.htm?help_id=474010
View Details前两天在VS2008下做个项目,用到了excel组件没有问题,但当把该项目在IIS下配置后,用浏览器浏览结果则不正确,网上说用dcom组件配置下,可是我按照要求配了,结果还是不对。 后来找到一个方法好用了。 Web.config中加了一句话:“<identity impersonate="true" userName="操作系统用户" password="用户密码"/>”,浏览…,结果正确,后来我就在网上查了下这句话的作用,MSDN是这样说的: 1、模拟 IIS 验证的帐户或用户 若要在收到 ASP.NET 应用程序中每个页的每个请求时模拟 Microsoft Internet 信息服务 (IIS) 身份验证用户,必须在此应用程序的 Web.config 文件中包含 <identity> 标记,并将 impersonate 属性设置为 true 2、为 ASP.NET 应用程序的所有请求模拟特定用户 若要为 ASP.NET 应用程序的所有页面上的所有请求模拟特定用户,可以在该应用程序的 Web.config 文件的 <identity> 标记中指定 userName 和 password 属性。例如: <identity impersonate="true" userName="accountname" password="password" /> from:http://blog.csdn.net/lazyleland/article/details/7726528
View Details1. 全部 Activity 可继承自 BaseActivity,便于统一风格与处理公共事件,构建对话框统一构建器的建立,万一需要整体变动,一处修改到处有效。 2. 数据库表段字段常量和 SQL 逻辑分离,更清晰,建议使用 Lite 系列框架 LiteOrm 库,超级清晰且重心可以放在业务上不用关心数据库细节。 3. 全局变量放全局类中,模块私有放自己的管理类中,让常量清晰且集中. 4. 不要相信庞大的管理类的东西会带来什么好处,可能是一场灾难,而要时刻注意单一职责原则,一个类专心做好一件事情更为清晰。 5. 如果数据没有必要加载,数据请务必延迟初始化,谨记为用户节省内存,总不会有坏处。 6. 异常抛出,在合适的位置处理或者集中处理,不要搞的到处是 catch,混乱且性能低,尽量不要在循环体中捕获异常,以提升性能。 7. 地址引用链长时(3 个以上指向)小心内存泄漏,和警惕堆栈地址指向,典型的易发事件是:数据更新了,ListView 视图却没有刷新,这时 Adapter 很可能指向并的并不是你更新的数据容器地址(一般为 List)。 8. 信息同步:不管是数据库还是网网络操作,新插入的数据注意返回 ID(如果没有赋予唯一 ID),否则相当于没有同步。 9. 多线程操作数据库时,db 关闭了会报错,也很可能出现互锁的问题,推荐使用事务,推荐使用自动化的 LiteOrm 库操作。 10. 做之前先考虑那些可以公用,资源,layout,类,做一个结构、架构分析以加快开发,提升代码可复用度。 11. 有序队列操作 add、delete 操作时注意保持排序,否则你会比较难堪喔。 12. 数据库删除数据时,要注意级联操作避免出现永远删不掉的脏数据喔。 13. 关于形参实参:调用函数时参数为基本类型传的是值,即传值;参数为对象传递的是引用,即传址。 14. listview 在数据未满一屏时,setSelection 函数不起作用;ListView 批量操作时各子项和视图正确对应,可见即所选。 15 控制 Activity 的代码量,保持主要逻辑清晰。其他类遵守 SRP(单一职能),ISP(接口隔离)原则。 16. arraylist 执行 remove 时注意移除 int 和 Integer 的区别。你懂得。 17. Log 请打上 Tag,调试打印一定要做标记,能定位打印位置,否则尴尬是:不知道是哪里在打印。 18. 码块/常量/资源可以集中公用的一定共用,即使共用逻辑稍复杂一点也会值得,修改起来很轻松,修改一种,到处有效。 19. setSelection 不起作用,尝试 smoothScrollToPosition。ListView 的 LastVisiblePosition(最后一个可见子项)会随着 getView 方法执行位置不同变动而变。 20. 与 Activity 通讯使用 Handler 更方便; 如果你的框架回调链变长,考虑监听者模式简化回调。 […]
View Details|
1 |
在注册表中也搜不到相关wgatray.exe的项,但在仔细地搜索了注册表后,还是找到了这个的可恶东西。HKEY_LOCAL_MACHINE\SOFTWARE\microsoft\Windows NT\ CurrentVersion\Winlogon\Notify\WgaLogon,删除它,重新启动(一定要重起要不然删不了C盘的文件), wgatray.exe就不会自动启动了,再把C:\windows\system 32中的wgatray.exe删除,再搜索一下,在另外的文件夹下还有,统统删除,重起.然后再进HKEY_LOCAL_MACHINE\ SOFTWARE\microsoft\Windows NT\ CurrentVersion\Winlogon\Notify\WgaLogon,删除它终于OK了。 |
http://crm2.qq.com/page/portalpage/wpa.php?uin=4009991259&f=1&ty=1&aty=0&a=&from=6
View Details|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
#region 排序方法 #region 冒泡排序法 /// <summary> /// 冒泡排序法 /// </summary> /// <param name="list">数据列表</param> /// <param name="SortType">排序类型,选择是升序还是降序</param> public static void BubbleSort(int[] list, string SortType) { int j, temp; j = 1; while ((j < list.Length)) { for (int i = 0; i < list.Length - j; i++) { bool Bl; if (SortType == "asc") { Bl = list[i] > list[i + 1]; } else if (SortType == "desc") { Bl = list[i] < list[i + 1]; } else { Bl = false; } if (Bl) { temp = list[i]; list[i] = list[i + 1]; list[i + 1] = temp; } } j++; } } #endregion 冒泡排序法 #region 选择排序法 /// <summary> /// 选择排序法 /// </summary> /// <param name="list">数据列表</param> public static void ChoiceSort(int[] list) { int min; for (int i = 0; i < list.Length - 1; i++) { min = i; for (int j = i + 1; j < list.Length; j++) { if (list[j] < list[min]) min = j; } int t = list[min]; list[min] = list[i]; list[i] = t; } } #endregion 选择排序法 #region 插入排序法 /// <summary> /// 插入排序法 /// </summary> /// <param name="list">数据列表</param> public static void InsertSort(int[] list) { for (int i = 1; i < list.Length; i++) { int t = list[i]; int j = i; while ((j > 0) && (list[j - 1] < t)) { list[j] = list[j - 1]; --j; } list[j] = t; } } #endregion 插入排序法 #region 希尔排序法 /// <summary> /// 希尔排序法 /// </summary> /// <param name="list">数据列表</param> public static void ShellSort(int[] list) { int inc; for (inc = 1; inc <= list.Length / 9; inc = 3 * inc + 1) ; for (; inc > 0; inc /= 3) { for (int i = inc + 1; i <= list.Length; i += inc) { int t = list[i - 1]; int j = i; while ((j > inc) && (list[j - inc - 1] > t)) { list[j - 1] = list[j - inc - 1]; j -= inc; } list[j - 1] = t; } } } #endregion 希尔排序法 #endregion 排序方法 |
移动端越来越火了,我们在开发过程中,总会碰到要和移动端打交道的场景,比如.NET和android或者iOS的打交道。为了让数据交互更安全,我们需要对数据进行加密传输。今天研究了一下,把几种语言的加密都实践了一遍,实现了.NET,java(android),iOS都同一套的加密算法,下面就分享给大家。 AES加密有多种算法模式,下面提供两套模式的可用源码。 加密方式: 先将文本AES加密 返回Base64转码 解密方式: 将数据进行Base64解码 进行AES解密 一、CBC(Cipher Block Chaining,加密块链)模式 是一种循环模式,前一个分组的密文和当前分组的明文异或操作后再加密,这样做的目的是增强破解难度. 密钥 密钥偏移量 java/adroid加密AESOperator类:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
package com.bci.wx.base.util; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; /** * AES 是一种可逆加密算法,对用户的敏感信息加密处理 对原始数据进行AES加密后,在进行Base64编码转化; */ public class AESOperator { /* * 加密用的Key 可以用26个字母和数字组成 此处使用AES-128-CBC加密模式,key需要为16位。 */ private String sKey = "smkldospdosldaaa";//key,可自行修改 private String ivParameter = "0392039203920300";//偏移量,可自行修改 private static AESOperator instance = null; private AESOperator() { } public static AESOperator getInstance() { if (instance == null) instance = new AESOperator(); return instance; } public static String Encrypt(String encData ,String secretKey,String vector) throws Exception { if(secretKey == null) { return null; } if(secretKey.length() != 16) { return null; } Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] raw = secretKey.getBytes(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); IvParameterSpec iv = new IvParameterSpec(vector.getBytes());// 使用CBC模式,需要一个向量iv,可增加加密算法的强度 cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] encrypted = cipher.doFinal(encData.getBytes("utf-8")); return new BASE64Encoder().encode(encrypted);// 此处使用BASE64做转码。 } // 加密 public String encrypt(String sSrc) throws Exception { Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); byte[] raw = sKey.getBytes(); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());// 使用CBC模式,需要一个向量iv,可增加加密算法的强度 cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8")); return new BASE64Encoder().encode(encrypted);// 此处使用BASE64做转码。 } // 解密 public String decrypt(String sSrc) throws Exception { try { byte[] raw = sKey.getBytes("ASCII"); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes()); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);// 先用base64解密 byte[] original = cipher.doFinal(encrypted1); String originalString = new String(original, "utf-8"); return originalString; } catch (Exception ex) { return null; } } public String decrypt(String sSrc,String key,String ivs) throws Exception { try { byte[] raw = key.getBytes("ASCII"); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); IvParameterSpec iv = new IvParameterSpec(ivs.getBytes()); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); byte[] encrypted1 = new BASE64Decoder().decodeBuffer(sSrc);// 先用base64解密 byte[] original = cipher.doFinal(encrypted1); String originalString = new String(original, "utf-8"); return originalString; } catch (Exception ex) { return null; } } public static String encodeBytes(byte[] bytes) { StringBuffer strBuf = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a'))); strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a'))); } return strBuf.toString(); } public static void main(String[] args) throws Exception { // 需要加密的字串 String cSrc = "[{\"request_no\":\"1001\",\"service_code\":\"FS0001\",\"contract_id\":\"100002\",\"order_id\":\"0\",\"phone_id\":\"13913996922\",\"plat_offer_id\":\"100094\",\"channel_id\":\"1\",\"activity_id\":\"100045\"}]"; // 加密 long lStart = System.currentTimeMillis(); String enString = AESOperator.getInstance().encrypt(cSrc); System.out.println("加密后的字串是:" + enString); long lUseTime = System.currentTimeMillis() - lStart; System.out.println("加密耗时:" + lUseTime + "毫秒"); // 解密 lStart = System.currentTimeMillis(); String DeString = AESOperator.getInstance().decrypt(enString); System.out.println("解密后的字串是:" + DeString); lUseTime = System.currentTimeMillis() - lStart; System.out.println("解密耗时:" + lUseTime + "毫秒"); } } |
.NET AES加密解密:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
using System; using System.Security.Cryptography; using System.Text; namespace AESDome { class Program { private static string key = "smkldospdosldaaa"; //key,可自行修改 private static string iv = "0392039203920300"; //偏移量,可自行修改 static void Main(string[] args) { string encrytpData = Encrypt("abc", key, iv); Console.WriteLine(encrytpData); string decryptData = Decrypt("5z9WEequVr7qtd+WoxV+Kw==", key, iv); Console.WriteLine(decryptData); Console.ReadLine(); } public static string Encrypt(string toEncrypt, string key, string iv) { byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key); byte[] ivArray = UTF8Encoding.UTF8.GetBytes(iv); byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt); RijndaelManaged rDel = new RijndaelManaged(); rDel.BlockSize = 128; rDel.KeySize = 256; rDel.FeedbackSize = 128; rDel.Padding = PaddingMode.PKCS7; rDel.Key = keyArray; rDel.IV = ivArray; rDel.Mode = CipherMode.CBC; ICryptoTransform cTransform = rDel.CreateEncryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Convert.ToBase64String(resultArray, 0, resultArray.Length); } public static string Decrypt(string toDecrypt, string key, string iv) { byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key); byte[] ivArray = UTF8Encoding.UTF8.GetBytes(iv); byte[] toEncryptArray = Convert.FromBase64String(toDecrypt); // 这里的模式,请保持和上面加密的一样。但源代码里,这个地方并没有修正,虽然也能正确解密。看到博客的朋友,请自行修改。 // 这是个人疏忽的地址,感谢@jojoka 的提醒。 RijndaelManaged rDel = new RijndaelManaged(); rDel.Key = keyArray; rDel.IV = ivArray; rDel.Mode = CipherMode.CBC; rDel.Padding = PaddingMode.Zeros; rDel.BlockSize = 128; rDel.KeySize = 256; rDel.FeedbackSize = 128; rDel.Padding = PaddingMode.PKCS7; rDel.Key = keyArray; rDel.IV = ivArray; rDel.Mode = CipherMode.CBC; ICryptoTransform cTransform = rDel.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return UTF8Encoding.UTF8.GetString(resultArray); } } } |
iOS源码,请下载源码,源码里有包含。 java,.net,iOS,android通用AES加密解密源码:AES_CBC_ECB_android_java_ios_net通用模式 二、ECB(Electronic Code Book,电子密码本)模式 是一种基础的加密方式,密文被分割成分组长度相等的块(不足补齐),然后单独一个个加密,一个个输出组成密文。 只需要提供密码即可。 iOS,android,java已调通源码:AES_CBC_ECB_android_java_ios_net通用模式 AES在线加解密验证工具: http://www.seacha.com/tools/aes.html from:http://www.cnblogs.com/jys509/p/4768120.html
View Details