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

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

 2010-03-30 00:00:00 来源:WEB开发网   
核心提示: 清单 5. getOctetStringBytes() 方法publicbyte[]getOctetStringBytes(byte[]octetStringContents){//1.DeclareabytearraynamedfinalBytes,whichwill//holdalltheb


清单 5. getOctetStringBytes() 方法

  public byte[] getOctetStringBytes (byte[] octetStringContents) 
  { 
    //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 = octetStringContents.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)0x04; 
    //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. 
    for (int j=lengthBytesCount+1; j<totalBytesCount; j++) 
      finalBytes[j] = octetStringContents[j-(lengthBytesCount+1)]; 
    //10. Return the finalBytes array. 
    return finalBytes; 
  }//getOctetStringBytes 

上一页  5 6 7 8 9 10 

Tags:Kerberos JME 应用程序

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