如何使用java密码编码来验证

时间:2016-05-27 09:14:41

标签: java

我有来自cisco的示例代码,可以通过启用Tacacs +的Cisco NAM模块进行身份验证。

示例代码为:

    // Copyright (c) 2011 by Cisco Systems, Inc. All rights reserved.
 import java.security.*;
 import java.math.*;
 /** NAMEncode: Helper class for NAM web user authentication */
 public class NAMEncode {
   /** Encode the login password
    *  @return the encoded password
    */
   public static String encodePassword(String username, String password,String 
domain,String nonce,String pkey)
   { if(nonce != null && nonce.length() > 0)
       return encodeMD5(domain + nonce + username + password);
     else
       return encodeD_H(password, pkey);
   }


   /** Encode using Diffie-Hellman key exchange */
   public static String encodeD_H(String password, String pkey)
   { 
     BigInteger gen = new BigInteger("527d44089958ca1e", 16); // generator
     BigInteger mod = new BigInteger("5c13ada6c91d2ba3", 16); // modulus
     BigInteger spub = new BigInteger(pkey, 16); // server's public key
    BigInteger sec = new BigInteger(62, new java.util.Random());
     BigInteger pub = gen.modPow(sec, mod);  // client public key
     BigInteger shr = spub.modPow(sec, mod); // shared secret key

     String cpkey = pub.toString(16);
     while (cpkey.length() < 16)
    cpkey = "0"+cpkey;
    String shared = shr.toString(16);
     while (shared.length() < 16)
    shared = "0"+shared;
    shared = encodeMD5(shared);
    String encoded = one_pass(password, shared);
    return encoded + "," + cpkey;
    }

所以我可以使用网址http://nam_ip/auth/login.php?api=true,我看到三个参数:domain,nonce和pkey。 但是如何在java代码中传递这个并编译或运行这整个事情。 基本上我正在寻找一种方法来使这个java代码工作,我需要做什么?

来源是:http://www.cisco.com/c/en/us/td/docs/net_mgmt/network_analysis_module_software/5-1/developer/guide/api_guide.html#wp166632

0 个答案:

没有答案