`
balaschen
  • 浏览: 191616 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

sun base64解码实现

阅读更多
java 代码
  1. // Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2007-6-11 11:45:48   
  2. // Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!   
  3. // Decompiler options: packimports(3)    
  4. // Source File Name:   CharacterDecoder.java   
  5.   
  6. package sun.misc;   
  7.   
  8. import java.io.*;   
  9. import java.nio.ByteBuffer;   
  10.   
  11. // Referenced classes of package sun.misc:   
  12. //            CEStreamExhausted   
  13.   
  14. public abstract class CharacterDecoder   
  15. {   
  16.   
  17.     public CharacterDecoder()   
  18.     {   
  19.     }   
  20.   
  21.     protected abstract int bytesPerAtom();   
  22.   
  23.     protected abstract int bytesPerLine();   
  24.   
  25.     protected void decodeBufferPrefix(PushbackInputStream pushbackinputstream, OutputStream outputstream)   
  26.         throws IOException   
  27.     {   
  28.     }   
  29.   
  30.     protected void decodeBufferSuffix(PushbackInputStream pushbackinputstream, OutputStream outputstream)   
  31.         throws IOException   
  32.     {   
  33.     }   
  34.   
  35.     protected int decodeLinePrefix(PushbackInputStream pushbackinputstream, OutputStream outputstream)   
  36.         throws IOException   
  37.     {   
  38.         return bytesPerLine();   
  39.     }   
  40.   
  41.     protected void decodeLineSuffix(PushbackInputStream pushbackinputstream, OutputStream outputstream)   
  42.         throws IOException   
  43.     {   
  44.     }   
  45.   
  46.     protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream outputstream, int i)   
  47.         throws IOException   
  48.     {   
  49.         throw new CEStreamExhausted();   
  50.     }   
  51.   
  52.     protected int readFully(InputStream inputstream, byte abyte0[], int i, int j)   
  53.         throws IOException   
  54.     {   
  55.         for(int k = 0; k < j; k++)   
  56.         {   
  57.             int l = inputstream.read();   
  58.             if(l == -1)   
  59.                 return k != 0 ? k : -1;   
  60.             abyte0[k + i] = (byte)l;   
  61.         }   
  62.   
  63.         return j;   
  64.     }   
  65.   
  66.     public void decodeBuffer(InputStream inputstream, OutputStream outputstream)   
  67.         throws IOException   
  68.     {   
  69.         int j = 0;   
  70.         PushbackInputStream pushbackinputstream = new PushbackInputStream(inputstream);   
  71.         decodeBufferPrefix(pushbackinputstream, outputstream);   
  72.         try  
  73.         {   
  74.             do  
  75.             {   
  76.                 int k = decodeLinePrefix(pushbackinputstream, outputstream);   
  77.                 int i;   
  78.                 for(i = 0; i + bytesPerAtom() < k; i += bytesPerAtom())   
  79.                 {   
  80.                     decodeAtom(pushbackinputstream, outputstream, bytesPerAtom());   
  81.                     j += bytesPerAtom();   
  82.                 }   
  83.   
  84.                 if(i + bytesPerAtom() == k)   
  85.                 {   
  86.                     decodeAtom(pushbackinputstream, outputstream, bytesPerAtom());   
  87.                     j += bytesPerAtom();   
  88.                 } else  
  89.                 {   
  90.                     decodeAtom(pushbackinputstream, outputstream, k - i);   
  91.                     j += k - i;   
  92.                 }   
  93.                 decodeLineSuffix(pushbackinputstream, outputstream);   
  94.             } while(true);   
  95.         }   
  96.         catch(CEStreamExhausted cestreamexhausted)   
  97.         {   
  98.             decodeBufferSuffix(pushbackinputstream, outputstream);   
  99.         }   
  100.     }   
  101.   
  102.     public byte[] decodeBuffer(String s)   
  103.         throws IOException   
  104.     {   
  105.         byte abyte0[] = new byte[s.length()];   
  106.         s.getBytes(0, s.length(), abyte0, 0);   
  107.         ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(abyte0);   
  108.         ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();   
  109.         decodeBuffer(((InputStream) (bytearrayinputstream)), ((OutputStream) (bytearrayoutputstream)));   
  110.         return bytearrayoutputstream.toByteArray();   
  111.     }   
  112.   
  113.     public byte[] decodeBuffer(InputStream inputstream)   
  114.         throws IOException   
  115.     {   
  116.         ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();   
  117.         decodeBuffer(inputstream, ((OutputStream) (bytearrayoutputstream)));   
  118.         return bytearrayoutputstream.toByteArray();   
  119.     }   
  120.   
  121.     public ByteBuffer decodeBufferToByteBuffer(String s)   
  122.         throws IOException   
  123.     {   
  124.         return ByteBuffer.wrap(decodeBuffer(s));   
  125.     }   
  126.   
  127.     public ByteBuffer decodeBufferToByteBuffer(InputStream inputstream)   
  128.         throws IOException   
  129.     {   
  130.         return ByteBuffer.wrap(decodeBuffer(inputstream));   
  131.     }   
  132. }   
  133.   
  134.   
  135. // Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 2007-6-11 11:45:29   
  136. // Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!   
  137. // Decompiler options: packimports(3)    
  138. // Source File Name:   BASE64Decoder.java   
  139.   
  140. package sun.misc;   
  141.   
  142. import java.io.*;   
  143.   
  144. // Referenced classes of package sun.misc:   
  145. //            CharacterDecoder, CEFormatException, CEStreamExhausted   
  146.   
  147. public class BASE64Decoder extends CharacterDecoder   
  148. {   
  149.   
  150.     public BASE64Decoder()   
  151.     {   
  152.         decode_buffer = new byte[4];   
  153.     }   
  154.   
  155.     protected int bytesPerAtom()   
  156.     {   
  157.         return 4;   
  158.     }   
  159.   
  160.     protected int bytesPerLine()   
  161.     {   
  162.         return 72;   
  163.     }   
  164.   
  165.     protected void decodeAtom(PushbackInputStream pushbackinputstream, OutputStream outputstream, int i)   
  166.         throws IOException   
  167.     {   
  168.         byte byte0 = -1;   
  169.         byte byte1 = -1;   
  170.         byte byte2 = -1;   
  171.         byte byte3 = -1;   
  172.         if(i < 2)   
  173.             throw new CEFormatException("BASE64Decoder: Not enough bytes for an atom.");   
  174.         int j;   
  175.         do  
  176.         {   
  177.             j = pushbackinputstream.read();   
  178.             if(j == -1)   
  179.                 throw new CEStreamExhausted();   
  180.         } while(j == 10 || j == 13);   
  181.         decode_buffer[0] = (byte)j;   
  182.         j = readFully(pushbackinputstream, decode_buffer, 1, i - 1);   
  183.         if(j == -1)   
  184.             throw new CEStreamExhausted();   
  185.         if(i > 3 && decode_buffer[3] == 61)   
  186.             i = 3;   
  187.         if(i > 2 && decode_buffer[2] == 61)   
  188.             i = 2;   
  189.         switch(i)   
  190.         {   
  191.         case 4// '\004'   
  192.             byte3 = pem_convert_array[decode_buffer[3] & 0xff];   
  193.             // fall through   
  194.   
  195.         case 3// '\003'   
  196.             byte2 = pem_convert_array[decode_buffer[2] & 0xff];   
  197.             // fall through   
  198.   
  199.         case 2// '\002'   
  200.             byte1 = pem_convert_array[decode_buffer[1] & 0xff];   
  201.             byte0 = pem_convert_array[decode_buffer[0] & 0xff];   
  202.             // fall through   
  203.   
  204.         default:   
  205.             switch(i)   
  206.             {   
  207.             case 2// '\002'   
  208.                 outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));   
  209.                 break;   
  210.   
  211.             case 3// '\003'   
  212.                 outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));   
  213.                 outputstream.write((byte)(byte1 << 4 & 0xf0 | byte2 >>> 2 & 0xf));   
  214.                 break;   
  215.   
  216.             case 4// '\004'   
  217.                 outputstream.write((byte)(byte0 << 2 & 0xfc | byte1 >>> 4 & 3));   
  218.                 outputstream.write((byte)(byte1 << 4 & 0xf0 | byte2 >>> 2 & 0xf));   
  219.                 outputstream.write((byte)(byte2 << 6 & 0xc0 | byte3 & 0x3f));   
  220.                 break;   
  221.             }   
  222.             break;   
  223.         }   
  224.     }   
  225.   
  226.     private static final char pem_array[] = {   
  227.         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',    
  228.         'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',    
  229.         'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',    
  230.         'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',    
  231.         'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',    
  232.         'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',    
  233.         '8', '9', '+', '/'   
  234.     };   
  235.     private static final byte pem_convert_array[];   
  236.     byte decode_buffer[];   
  237.   
  238.     static    
  239.     {   
  240.         pem_convert_array = new byte[256];   
  241.         for(int i = 0; i < 255; i++)   
  242.             pem_convert_array[i] = -1;   
  243.   
  244.         for(int j = 0; j < pem_array.length; j++)   
  245.             pem_convert_array[pem_array[j]] = (byte)j;   
  246.   
  247.     }   
  248. }  

 

  • doc.rar (5.5 KB)
  • 下载次数: 40
  • Base64.rar (6.5 KB)
  • 描述: novell实现
  • 下载次数: 56
分享到:
评论

相关推荐

    sun.misc.BASE64Encoder源码及jar包

    而`sun.misc.BASE64Encoder`和`BASE64Decoder`虽然存在潜在问题,但它们可以帮助开发者快速实现Base64编码和解码。为了遵循最佳实践,建议使用`java.util.Base64`包提供的API来替代这些非公开类。

    sun.misc.BASE64Decoder

    Java 8及以后的版本提供了`java.util.Base64`类,它是官方推荐的Base64编码和解码的标准实现。`java.util.Base64.Decoder`接口提供了与`sun.misc.BASE64Decoder`类似的功能,可以用来解码Base64编码的字符串。例如,...

    base64_sun.misc.BASE64Decoder.zip

    总的来说,Base64编码和解码是信息技术中基础且重要的概念,`sun.misc.BASE64Decoder`则是Java早期实现Base64解码的一个工具。尽管存在更好的替代方案,理解它的原理和用法仍然是有价值的,特别是在处理旧代码或理解...

    sun base64加密解密,含sun的base64 jar包

    通常,这样的类会封装`java.util.Base64`或其他Base64实现,提供方便的静态方法来进行Base64编码和解码操作。 在实际开发中,为了保持代码的兼容性和可维护性,我们应该避免使用`sun.misc`包中的类,而应该使用标准...

    sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder;

    在本例中,`sun.misc.BASE64Decoder.jar`可能包含`BASE64Decoder`和`BASE64Encoder`类的实现,供那些仍需使用这些非标准组件的项目使用。 总的来说,尽管`sun.misc.BASE64Decoder`和`BASE64Encoder`在某些老项目中...

    sun.misc.BASE64Encoder.jar包

    `sun.misc.BASE64Encoder`和`sun.misc.BASE64Decoder`就是这样的两个类,它们分别用于Base64编码和解码。 Base64是一种用于将二进制数据转换为可打印ASCII字符的编码方式,常用于在网络上传输二进制数据,如电子...

    sun.misc.BASE64Encoder 加密源码+完整包.rar

    `sun.misc`包中的这些类是Java早期版本提供的非标准API,主要用于内部使用,但在某些场景下,开发者会利用它们来实现Base64的编码和解码功能。 **Base64编码原理:** Base64编码基于64个可打印的ASCII字符,将每3个...

    RSA加密JAVA实现+sun.misc.BASE64Decoder.jar

    这个Java实现的示例提供了RSA加密和解密的功能,并且结合了`sun.misc.BASE64Decoder.jar`来处理Base64编码,使得加密后的密文能够以可读的形式存储和传输。 首先,RSA的核心原理基于大数因子分解的困难性。每个RSA...

    sun.misc.BASE64Decoder.jar 绿色官方版

    《深入理解sun.misc.BASE64Decoder.jar:一个基础的Base64解码工具》 在IT行业中,数据编码和解码是日常开发中不可或缺的一部分,其中Base64编码是一种广泛应用于网络传输和存储中的编码方式。它将二进制数据转化...

    sun的BASE64Decoder

    【标题】"sun的BASE64Decoder"是一个与编码解码相关的工具,源自sun公司,主要用于处理BASE64编码的数据。BASE64是一种常见的数据编码方式,尤其在互联网通信、文件传输以及电子邮件中广泛使用。它将二进制数据转换...

    Java基于Base64实现编码解码图片文件

    "Java基于Base64实现编码解码图片文件" Java基于Base64实现编码解码图片文件是Java语言中的一种常见的编码解码实现方式。Base64是一种常用的字符编码,在很多地方都会用到,但它并不是安全领域下的加密解密算法,...

    sun.misc.BASE64Decoder.jar

    在Java编程语言中,`sun.misc.BASE64Decoder`是一个重要的类,用于处理Base64编码的解码工作。Base64是一种常见的数据编码方法,它将任意的二进制数据转换为ASCII字符串,以便在网络传输或者存储时避免非ASCII字符的...

    sun.misc.base64decoder

    在提供的压缩包文件中,"sun.misc.BASE64Decoder.jar"可能包含了`sun.misc.Base64Decoder`类的实现,可以被用来在不支持Java官方Base64 API的旧版本Java环境中进行Base64解码。而"更新日志.txt"文件可能是该jar包的...

Global site tag (gtag.js) - Google Analytics