zoukankan      html  css  js  c++  java
  • 腾讯网页登陆的加密机制

    现在讲解一下如何把明文的1234加密成09967317CCFC266ADA83C9B1BEA30825(这么恶心的密码)

          这个是腾讯加密的JavaScript脚本 密码加密JavaScript。初步看了一下觉得相当之恶心,所以在网上搜索了半天找到的一点线索就是  3次MD5加密后转换大些 + 验证码转换大写,再次MD5加密可是我按照这方法试了得到的结果却不是正确的。百思不得其解,求助了园子里认识的朋友,他给我发了段C#的代码,确实可以得到正确的。代码如下:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Security.Cryptography;
    using System.Text.RegularExpressions;
    using System.Collections;

    namespace QQ校友助手
    {
    class QQPassword
    {
    public static string binl2hex(byte[] buffer)
    {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < buffer.Length; i++)
    {
    builder.Append(buffer[i].ToString("x2"));
    }
    return builder.ToString();
    }
    public static string md5_3(string input)
    {
    MD5 md = MD5.Create();
    byte[] buffer = md.ComputeHash(Encoding.Default.GetBytes(input));
    buffer = md.ComputeHash(buffer);
    buffer = md.ComputeHash(buffer);
    return binl2hex(buffer);
    }

    public static string md5(string input)
    {
    byte[] buffer = MD5.Create().ComputeHash(Encoding.Default.GetBytes(input));
    return binl2hex(buffer);
    }

    public static string getPassword(string password, string verifycode)
    {
    return md5(md5_3(password).ToUpper() + verifycode.ToUpper()).ToUpper();
    }

    }
    }

         Encoding.Default.GetBytes(input)获取的是字符串的ASCII码。用VS跟踪调试了好久,发现问题出在 C#的computehash是初级hash,得到的并不是16进制的MD5字符串,需要经过binl2hex才能转换成MD5字符串。也就是说初级hash了3次,才合并大写验证码进行最后一次MD5加密

  • 相关阅读:
    web集群和分布式服务以及消息补偿机制几种方案
    什么是幂等性
    Dubbo面试常见问题
    mysql 缓存机制
    mysql面试题
    在IDEA中用Gradle构建项目时使用lombok以依赖出现出错
    jdbcType与javaType的对应关系
    通用Mapper的使用
    Java各种对象(PO,BO,VO,DTO,POJO,DAO,Entity,JavaBean,JavaBeans)的区分
    dubbo面试题
  • 原文地址:https://www.cnblogs.com/yibinboy/p/2310165.html
Copyright © 2011-2022 走看看