Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String base64( String data ){
- String vals = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890+/=";
- System.Text.StringBuilder buffer = new System.Text.StringBuilder();
- char[] in = data.ToCharArray(0, data.Length);
- int read = 0;
- int i = 0;
- while( i < data.Length ){
- if( bufout >= bufferlen - read / 2 )
- break;
- int reading;
- if( read <= 2 ){
- reading = ( in[i] >> (2-read) ) & 0x3F;
- }
- else{
- reading = ( ( in[i++] << read ) & 0xFF ) >> 2;
- reading += ( in[i] >> (8-read+2) ) & 0x3F;
- }
- read = ( read + 6 ) % 8;
- if( read == 0 ) i ++;
- buffer.Append( vals.Substring(reading, 1) );
- }
- while( read != 0 ){
- buffer.Append( "=" );
- read = ( read + 6 ) % 8;
- }
- return buffer.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement