快速业务通道

用Kerberos为J2ME应用程序上锁,第2部分 - 生成一个Kerberos票据请求 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-15
修正 。

现在再次检查第 10 步得到的经过奇偶修正的 8 字节块是不是弱密钥(就像在第 8 步中所做的那样 )。

第 11 步的结果是一个 Kerveros 客户机可以用来与 Kerberos 服务器进行通信的密钥。

现在看一下清单 11 中的 KerberosKey 类。这个类的 generateKey() 方法实现了上面描述的 11 步 密钥生成算法。

喘Kerberos葎J2ME哘喘殻會貧迄?及2何蛍 - 伏撹匯倖Kerberos同象萩箔(10)

扮寂:2011-08-05 IBM Faheem Khan

賠汽 11. KerberosKey 窃

import org.bouncycastle.crypto.params.ParametersWithRandom; import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.generators.DESKeyGenerator; import org.bouncycastle.crypto.params.DESParameters; import org.bouncycastle.crypto.engines.DESEngine; import org.bouncycastle.crypto.params.KeyParameter; import org.bouncycastle.crypto.params.ParametersWithIV; public class KerberosKey {    private CBCBlockCipher cipher;    private KeyParameter kp;    private ParametersWithIV iv;    private byte kerberosKey[];    private ASN1DataTypes asn1;    private String principalID;    public KerberosKey(String userName, String password, String realmName)    {      kerberosKey = new byte[8];      kerberosKey = generateKey (password, realmName, userName);    }//KerberosKey    public byte[] generateKey (String password, String realmName, String  userName)    {      //Step 1:      String str = new String (password + realmName + userName);      byte secretKey [] = new byte[8];      //Step 2:      byte encodedByteArray[] = encodeString(str);      //Step 3:      byte paddedByteArray[] = padString(encodedByteArray);      //Step 4:      int i = paddedByteArray.length / 8;      //Step 5:      for(int x=0; x<i; x++)      {        byte blockValue1[] = new byte [8];        System.arraycopy (paddedByteArray, x*8, blockValue1, 0, 8);        if(x % 2 == 1)        {          byte tempbyte1 = 0;          byte tempbyte2 = 0;          byte blockValue2[] = new byte [8];          for (int y=0; y<8; y++)          {            tempbyte2 = 0;            for (int z=0; z<4; z++)            {              tempbyte2 = (byte) ((1<<(7-z)) & 0xff);              tempbyte1 |= (blockValue1[y] & tempbyte2) >>>  (7-2*z);              tempbyte2 = 0;            }            for (int z=4; z<8; z++)            {              tempbyte2 = (byte) ((1<<(7-z)) & 0xff);              tempbyte1 |= (blockValue1[y] & tempbyte2) <<  (2*z-7);              tempbyte2 = 0;            }            blockValue2 [7-y] = tempbyte1;            tempbyte1 = 0;          }//outer for

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号