WEB开发网
开发学院软件开发Java 用 Kerberos 为 J2ME 应用程序上锁,第 2 部分: 生... 阅读

用 Kerberos 为 J2ME 应用程序上锁,第 2 部分: 生成一个 Kerberos 票据请求

 2010-03-30 00:00:00 来源:WEB开发网   
核心提示: 清单 4. getGeneralStringBytes() 方法publicbyte[]getGeneralStringBytes(StringgeneralStringContent){//1.DeclareabytearraynamedfinalBytes,whichwill//holdal

清单 4. getGeneralStringBytes() 方法

  public byte[] getGeneralStringBytes (String generalStringContent) 
  { 
    //1. Declare a byte array named finalBytes, which will 
    //  hold all the bytes of the ASN.1 byte array representation. 
    byte finalBytes[]; 
    //2. Calculate the number of bytes required to hold the 
    //  contents part of the ASN.1 byte array representation. 
    int contentBytesCount = generalStringContent.length(); 
    //3. Use the getLengthBytes() method of Listing 3 to author 
    //  the length bytes. Store the length bytes in 
    //  an array named lengthBytes. 
    byte lengthBytes[] = getLengthBytes(contentBytesCount ); 
    //4. Get the number of bytes in the lengthBytes array. 
    int lengthBytesCount = lengthBytes.length; 
    //5. Calculate the number of bytes required to hold the complete 
    //  ASN.1 byte array representation (the sum total of the number 
    //  of tag bytes, length bytes, and content bytes). 
    //  Store the number of bytes in a variable named totalBytesCount. 
    int totalBytesCount = 1 + lengthBytesCount + contentBytesCount ; 
    //6. Instantiate the finalBytes array to totalBytesCount size. 
    finalBytes = new byte[totalBytesCount]; 
    //7.Copy the tag byte at the start of the finalBytes array. 
    finalBytes[0] = (byte)0x1B; 
    //8. Copy the length bytes from the lengthBytes array 
    //  to the finalBytes array just after the tag byte. 
    for (int i=0; i < lengthBytes.length; i++) 
      finalBytes[i+1] = lengthBytes[i]; 
    //9. Copy the content bytes to the finalBytes array just after the length bytes. 
    byte tempString[] = generalStringContent.getBytes(); 
    for (int j=lengthBytesCount+1; j<totalBytesCount; j++) 
      finalBytes[j] = tempString[j-(lengthBytesCount+1)]; 
    //10. Return the finalBytes array. 
    return finalBytes; 
  }//getGeneralStringBytes 

上一页  4 5 6 7 8 9 10  下一页

Tags:Kerberos JME 应用程序

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接