- 浏览: 70334 次
- 性别:
- 来自: 常州
文章分类
最新评论
-
yx1989:
不错,讲解得很清楚
Scanner的用法误区 -
lijunjie337:
你这是DES还是3DES啊??
JAVA中3des加密算法 -
啸笑天:
...
关键字 过滤算法 -
javamvp:
看看
策略设计模式 -
bianku:
...
成为Java高手的25个学习要点
SIPC的认证算法,支持SHA1和MD5。 import java.io.UnsupportedEncodingException; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Random; /** * @author zackel * @date 2007-11-22 21:38:07 * @project */ public class GenAuthResponse { // Fields private String cnonce; private String domain; private String nonce; private String password; private static Random random; private String sid; private boolean usingSHA1=false; private String salt; private String encryptPassword; public void setSalt(String salt) { this.salt = salt; } public String getEncryptPassword() { return encryptPassword; } public void setEncryptPassword(String encryptPassword) { this.encryptPassword = encryptPassword; } public String getSalt() { return salt; } // public void setSalt(String salt) { // this.salt = salt; // } public boolean isUsingSHA1() { return usingSHA1; } public void setUsingSHA1(boolean usingSHA1) { this.usingSHA1 = usingSHA1; } public String getCnonce() { return this.cnonce; } public void setCnonce(String cnonce) { this.cnonce = cnonce; } public String getDomain() { return domain; } public void setDomain(String domain) { this.domain = domain; } public String getNonce() { return nonce; } public void setNonce(String nonce) { this.nonce = nonce; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSid() { return sid; } public void setSid(String sid) { this.sid = sid; } // Methods public GenAuthResponse(String sid, String password, String domain, String nonce) { this.sid = sid; this.password = password; this.domain = domain; this.nonce = nonce; Calendar cal = new GregorianCalendar(); int seed = cal.get(Calendar.DAY_OF_YEAR) * 0xf4240; seed += cal.get(Calendar.HOUR) * 0x2710; seed += cal.get(Calendar.MINUTE) * 100; seed += cal.get(Calendar.SECOND); // random = new Random(System.currentTimeMillis()); random = new Random(seed); this.cnonce = GenCNonce(); this.salt=GenSalt(); // System.out.println(salt); } private static String BinToHex(byte[] binary) { // StringBuilder builder = new StringBuilder(); // for(byte num : binary) // { // int n = num; // if (n < 0) // n = n &0xff; // // if ((int)n > 15) // { // builder.append(String.format("%X",n)); // // } // else // { // builder.append(String.format("0%X",n)); // // } // } //// System.out.println(builder.toString()); // return builder.toString(); if (binary == null) return "null"; if (binary.length == 0) return ""; StringBuilder buf = new StringBuilder(); for (int i = 0; i < binary.length; i++) { if (binary[i] < 0) buf.append(Integer.toHexString(binary[i]&0xff)); else if (binary[i] < 16) { buf.append('0'); buf.append(Integer.toHexString(binary[i])); } else { buf.append(Integer.toHexString(binary[i])); } } return buf.toString().toUpperCase(); } private String GenH1(byte[] key) { String s = String.format(":%s:%s", this.nonce, this.getCnonce()); // System.out.println("nonce:"+this.nonce ); // System.out.println("Cnonce:"+this.getCnonce()); // System.out.println(s); byte[] bytes; try { // bytes = s.getBytes("UTF-8"); bytes=new String(s.getBytes(),"utf-8").getBytes(); // System.out.println("h1 bytes:"+this.BinToHex(bytes)); byte[] array = new byte[key.length + bytes.length]; System.arraycopy(key,0,array,0,key.length); System.arraycopy(bytes, 0, array, key.length, bytes.length); // System.out.println("h1 array:"+this.BinToHex(array)); return MD5ToHex(array); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } private String GenH2() { String s = String.format("REGISTER:%s", this.sid); // System.out.println(s); try { // return MD5ToHex(s.getBytes("UTF-8")); return MD5ToHex(new String(s.getBytes(),"utf-8").getBytes()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } private byte[] GenKey() { if(this.usingSHA1==true){ String s1 = String.format("%s:%s:", this.sid, this.domain); // System.out.println(s1); try { this.encryptPassword=DoHashPassword(this.password); // System.out.println("GenKey enc psw:"); // System.out.println(this.encryptPassword); byte[] bytes=(new String(s1.getBytes(),"utf-8").getBytes()); // System.out.println("GenKey bytes:"+BinToHex(bytes)); byte[] src=this.HexToBin(this.encryptPassword.substring(8));//和C#定义不一样? // System.out.println("psw0-8:"+BinToHex(src)); // byte[] src=this.HexToBin(this.salt); byte[] dst=new byte[bytes.length +src.length ]; System.arraycopy(bytes,0,dst,0,bytes.length); System.arraycopy(src,0,dst,bytes.length,src.length); // System.out.println("GenKey dst:"+BinToHex(dst)); return new SHA1().getDigestOfBytes(dst); } catch (UnsupportedEncodingException e) { // TODO 自动生成 catch 块 e.printStackTrace(); } } String s = String.format("%s:%s:%s", this.sid, this.domain, this.password); // System.out.println(s); try { // return MD5(s.getBytes("UTF-8")); return MD5(new String(s.getBytes(),"utf-8").getBytes()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } public String GenResponse() { byte[] key = this.GenKey(); // System.out.println("Key:"); // System.out.println(this.BinToHex(key)); String str = this.GenH1(key); // System.out.println("H1:"); // System.out.println(str); String str2 = this.GenH2(); // System.out.println("H2:"); // System.out.println(str2); return this.GenResponse(str, str2); } private String GenResponse(String h1, String h2) { String s = String.format("%s:%s:%s", h1, this.nonce, h2); // System.out.println(s); try { // return MD5ToHex(s.getBytes("UTF-8")); return MD5ToHex(new String(s.getBytes(),"utf-8").getBytes()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } private String GenCNonce() { int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; synchronized (random) { num = random.nextInt(); num2 = random.nextInt(); num3 = random.nextInt(); num4 = random.nextInt(); } if ((num >> 0x18) < 0x10) { num += 0x10000000; } if ((num2 >> 0x18) < 0x10) { num2 += 0x10000000; } if ((num3 >> 0x18) < 0x10) { num3 += 0x10000000; } if ((num4 >> 0x18) < 0x10) { num4 += 0x10000000; } return String.format("%X%X%X%X", new Object[] { num, num2, num3, num4 }); // } private static byte[] HexToBin(String hex) { hex=hex.toUpperCase(); if ((hex == null) || (hex.length() < 1)) { return new byte[0]; } int num = hex.length() / 2; byte[] buffer = new byte[num]; num *= 2; for (int i = 0; i < num; i++) { // System.out.println(hex.substring(i, i+2)); char c1,c2; c1=hex.substring(i,i+1).charAt(0); c2=hex.substring(i+1, i+2).charAt(0); // System.out.println(c1); if(c1>='A') c1=(char) (10+c1-'A'); else c1=(char) (c1-'0'); if(c2>='A') c2=(char) (10+c2-'A'); else c2=(char) (c2-'0'); // System.out.println(c1-'A'); // System.out.println(c2); // System.out.println(c1*16+c2); int num3=c1*16+c2; // int num3 = Integer.parseInt(hex.substring(i, i+2)); buffer[i / 2] = (byte) num3; i++; } // System.out.println(BinToHex(buffer)); return buffer; } private byte[] MD5(byte[] data) { return MD5Util.MD5Encode(data); } private String MD5ToHex(byte[] data) { // data = MD5(data); return BinToHex(MD5(data)); } public String DoHashPassword(String _password){ try { return DoHashPassword(new String(_password.getBytes(),"utf-8").getBytes(),this.HexToBin(this.salt)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; } public String DoHashPassword(byte[] password, byte[] b0) { SHA1 sha=SHA1.Create(); byte[] src = sha.getDigestOfBytes(password); // System.out.println("psw sha1:"); // System.out.println(this.BinToHex(src)); for (int i = 0; i < password.length; i++) { password[i] = 0; } byte[] dst = new byte[b0.length + src.length]; System.arraycopy(b0, 0, dst, 0, b0.length); System.arraycopy(src, 0, dst, b0.length, src.length); byte[] buffer3 = sha.getDigestOfBytes(dst); // System.out.println("buffer3 sha1:"); // System.out.println(this.BinToHex(buffer3)); byte[] buffer4 = new byte[b0.length + buffer3.length]; System.arraycopy(b0, 0, buffer4, 0, b0.length); System.arraycopy(buffer3, 0, buffer4, b0.length, buffer3.length); // System.out.println("enc psw:"); // System.out.println(this.BinToHex(buffer4)); return this.BinToHex(buffer4); } public String GenSalt(){ byte[] salt = new byte[4]; synchronized (random) { salt[0] = (byte)random.nextInt(255); salt[1] = (byte)random.nextInt(255); salt[2] = (byte)random.nextInt(255); salt[3] = (byte)random.nextInt(255); // System.out.println(salt[3]); return this.BinToHex(salt); // return salt; } } // public static String EncodePassword(byte[] password, byte[] b0) // { // using (SHA1 sha = SHA1.Create()) // { // byte[] src = sha.ComputeHash(password); // for (int i = 0; i < password.Length; i++) // { // password[i] = 0; // } // byte[] dst = new byte[b0.Length + src.Length]; // Buffer.BlockCopy(b0, 0, dst, 0, b0.Length); // Buffer.BlockCopy(src, 0, dst, b0.Length, src.Length); // byte[] buffer3 = sha.ComputeHash(dst); // byte[] buffer4 = new byte[b0.Length + buffer3.Length]; // Buffer.BlockCopy(b0, 0, buffer4, 0, b0.Length); // Buffer.BlockCopy(buffer3, 0, buffer4, b0.Length, buffer3.Length); // return BinaryToHex(buffer4); // } // } // public static String BinaryToHex(byte[] binary) // { // StringBuilder builder = new StringBuilder(); // for(byte num:binary) // { // if (num > 15) // { // builder.("{0:X}", num); // } // else // { // builder.AppendFormat("0{0:X}", num); // } // } // return builder.toString(); // } // public static void main(String[] args){ // GenAuthResponse genAuthResponse=new GenAuthResponse("759909","A","fetion.com.cn", "250BA679516452E860C02B1638D52849"); // genAuthResponse.setUsingSHA1(true); // genAuthResponse.setCnonce("798AC8BD240DABB21C9259C8148373F2"); // genAuthResponse.setSalt("FD761703"); // //// genAuthResponse.HexToBin("E0FF0100"); // System.out.println(genAuthResponse.GenResponse()); //// System.out.println(genAuthResponse.getCnonce()); // //// Random random = new Random(10); //// int i=random.nextInt(9); // int num3; //// System.out.println(num3 = Integer.parseInt("0x5A")); // // } }
发表评论
-
矩阵求逆算法
2009-06-04 08:40 1744/** * 求矩阵A的逆矩阵Ai *@param A ... -
赫夫曼编码
2009-06-04 08:38 1254/* Name: 赫夫曼编码 Copyright: 始 ... -
关键字 过滤算法
2009-06-04 08:37 3722因为过滤关键字机制到处可见,于是聪明的网友就会想到各种各样的方 ... -
关键字过滤解决方案
2009-06-04 08:36 1597关键字过滤功能自然无比重要,但是如果要在代码中对每个输入进行检 ... -
多优先级队列调度算法
2009-06-04 08:33 2784一、多优先级队列调度 ... -
堆排序算法的实现
2009-06-04 08:31 721#include <stdio.h> void ... -
递推关系算法
2009-06-04 08:29 776题目描述: 斐波那契研究的兔子是每隔两个月开始成熟,现在我 ... -
插入排序算法
2009-06-04 08:28 779思想:将整个数组分成已排(左边)和待排(右边)两个部分,开始时 ... -
并行排序算法
2009-06-04 08:26 1526今天早晨看到 蛙蛙池塘 ... -
n个元素的全排列算法
2009-06-04 08:21 1113/* * 输出n个元素的全排列 */ #inc ... -
MethodTable内存空间分配中加法运算算法
2009-06-04 08:20 741在分析MethodTable具体分配内存实现的时候,看到了计算 ... -
lockfree 算法
2009-06-04 08:17 1065lockfree的本质是乐观锁。也就是说,它假设多数情况下,别 ... -
java中的冒泡算法
2009-06-04 08:15 797public class SortDemo { pub ... -
JAVA中3des加密算法
2009-06-04 08:14 2390package test; /* * 当前文件:T ... -
排列方法
2008-11-23 14:17 772排序有很多种方法,常用的有三种:冒泡排序、选择排序、插入排序 ...
相关推荐
《综合即时通信接口规范SIP-C基础》 SIPC的认证算法java实现
SSK飚王SIPC001网络摄像头升级固件3501.1.2.0版(2014年1月24日发布)该驱动为飚王SIPC001网络摄像头升级固件,版本为3501.1.2.0。 该版固件做出了一下的更新和修复内容: 1、支持远程调用存储卡录像(AVI)文件; ...
sipC++扩展python.pdf
sipC++扩展python[收集].pdf
本文档描述了SIPC协议各个方面,包括基本原则,消息结构,消息模式等等。
codepenSIPC 前端设计开发平台
Prevcrim-“预防犯罪综合体(SIPC)”。 洛桑因普特人个人信息管理和格式管理专员根据独立性,连续性,连续性,连续性,统一性,连续性,统一性,统一性,统一性,统一性,统一性,统一性和统一性。 参加。 埃斯特...
以飞行实验中安装在同一个航空平台上的偏振扫描仪(POSP)和同时偏振相机(SIPC)为例,提出了一种对单幅SIPC图像及单扫描圈内POSP星下点邻近数据进行快速视场匹配的方法。通过POSP旋转扫描采集模式下的拖影权重系数模板,...
江苏科达公司产 IPC系统摄像机IP扫描工具及维护具
maskviews是一个简单的掩膜编辑工具,mocasim是一个蒙特卡罗模拟器,dbinternal是一个内部命令解释器,implant3d是一个蒙特卡罗3D实现,ghostprint是一个GNU工具,用于显示Postscript文件,stopping3d是一个停止表格...
class.curl.php class.fetion.php class.SIPC.php send.php 更改$sms->phone_num 及$sms->password参数 2.该程序默认调用/usr/local/nagios/ smservice.out该文件的内容为短信内容 用wget -qO- ...
通过N-琥珀酰亚胺5-(三正丁基锡)-3-吡啶甲酸酯(SPC),杨远友,昝亮彪,合成了用于胰岛素标记的偶联剂SPC,研究了标记条件、标记物[131I ]SIPC-insulin在体外的稳定性及在正常小鼠体内的分布。结果表明,在CH2Cl
预处理的sipc开发/测试集( data/ ) 孟加拉语和英语( vocab/ )的句法词汇模型 依存关系 的Python 3.7.3 PyTorch 1.2 赛顿 费斯 快速BPE 句子( Install CLI ) 音译 正则表达式 torchtext ( pip install ...
·设置位图导入位置控制常数[SETIMAGEINPOSCONTROLCONST/SIIPCC/SIPC] 根节点X(数值) 根节点Y(数值) 节点X间隔(数值) 节点Y间隔(数值) 6、删除了指令: ·设置导入位置控制常数[SETINPOSCONTROLCONST/SIPCC] 7、...