vc下如何实现对用户名何密码得BASE64编码!

lalala 2000-05-08 11:15:00
当代理服务器要输入用户名密码时,如何在VC下对username:password进行base64编码!
是否有vc下通过代理服务器(HTTP/1.0)(要通过用户名何密码得验证)访问资源得程序!
...全文
234 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lalala 2000-06-02
  • 打赏
  • 举报
回复
我任意编了个密码xubinwu:xl761013
通过jetcar,netants得到的编码是:
eHViaW53dTp4bDc2MTAxMw==
而你的程序得到的是:
eAAiaAA3dAA4bAA2MAAxMA==
lalala 2000-06-02
  • 打赏
  • 举报
回复
我的密码前几个是(由于安全问题,不能公布)xub......
通过你的程序得到eAAiaAA.......
而我通过jetcar里的proxy-Authorization的到编码为eHViaWF......
不知错在那里?
lalala 2000-05-10
  • 打赏
  • 举报
回复
编码不对,我通过与jetcar的Proxy-Authorization:Basic "mycode"测试发现编码不相符!
telan 2000-05-10
  • 打赏
  • 举报
回复
什么不对?
telan 2000-05-09
  • 打赏
  • 举报
回复
看看:http://www.csdn.net/expert/TopicView.asp?id=7157
telan 2000-05-09
  • 打赏
  • 举报
回复
// Base64.h: interface for the CBase64 class.
//////////////////////////////////////////////////////////////////////
#ifndef __BASE64__H__INCLUDED__
#define __BASE64__H__INCLUDED__


// CBase64 (64编码)
class CBase64
{
public:
CBase64();
virtual ~CBase64();

int Decode( LPCTSTR pszDecoding, LPTSTR pszOutput, int nSize ) ;
int Encode( LPCTSTR pszEncoding, LPTSTR pszOutput, int nSize ) ;
int GetOutSize( int nSize , BOOL bEncode);
private:
ReadBits( LPCTSTR pszEncoding,int nSize, int nIndex);
int m_nInSize;
int m_nOutSize;
};

#endif // __BASE64__H__INCLUDED__





// Base64.cpp: implementation of the CBase64 class.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Base64.h"

TCHAR BASE64_TAB[] = _T( "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" );
int BASE64_MASK[] = {0,1,3,7,15,31,63};
//////////////////////////////////////////////////////////////////////
// 构造函数/析构函数
//////////////////////////////////////////////////////////////////////
CBase64::CBase64()
{
m_nInSize = 0;
m_nOutSize = 0;
}

CBase64::~CBase64()
{
}

int CBase64::ReadBits( LPCTSTR pszEncoding,int nSize, int nIndex)
{
int nTotalBits = nSize*8;
int nStartBit = nIndex*6;

if( nStartBit >= nTotalBits )
return 64; // '='

int nStartChar = nStartBit/8;
int nHaveBits = (nStartChar+1)*8-nStartBit;
char ch,ch1;

switch( nHaveBits )
{
case 8:
ch = pszEncoding[nStartChar];
ch >>=2;
break;
case 6:
ch = pszEncoding[nStartChar];
break;
case 4:
case 2:
ch = pszEncoding[nStartChar];
ch&= BASE64_MASK[nHaveBits];
ch <<=(6-nHaveBits);
if( nStartChar < nSize-1 )
{
ch1 = pszEncoding[nStartChar+1];
ch1 >>= (nHaveBits+2);
ch1&= BASE64_MASK[6-nHaveBits];
ch and = ch1;
}
break;
}
ch &= 63;
return (int)ch;
}


// 解码 〔字符串〕
int CBase64::Decode( LPCTSTR pszDecoding, LPTSTR pszOutput, int nSize )
{
int nDecode[ 256 ];
if( ( pszDecoding == NULL ) and and
( pszOutput == NULL ) )
return (-1);

// 建立解码表
for( int i = 0; i < 256; i++ )
nDecode[i] = -2; // 忽略
for( i=0; i < 64; i++ )
nDecode[ BASE64_TAB[ i ] ] = i;
nDecode['='] = -1; // 结束


int ch;
int nIndex,nDigit;
char chOut = 0;
int chRemain = 0;
int nBitsRemain = 0;
int nBitsHave = 0;
int nBits = 0;

m_nOutSize = 0;


for( nIndex = 0, m_nOutSize = 0; nIndex < nSize; nIndex++ )
{
ch = pszDecoding[ nIndex ];
nDigit = nDecode[ ch ];

if( nDigit >= 0 )
{
nBits = (8-nBitsHave >=6 )?6:(8-nBitsHave);
nBitsHave += nBits;
nBitsRemain = 6-nBits;
chOut <<= nBits;
chOut and = ( (nDigit>>(6-nBits)) & BASE64_MASK[nBits]);
if( nBitsHave == 8)
{
pszOutput[m_nOutSize++] = (char)chOut;
chOut = nDigit & BASE64_MASK[6-nBits];
nBitsHave = 6-nBits;
}
}
else if( nDigit == -1 )
{
if( nBitsRemain > 0)
pszOutput[m_nOutSize++] = (char)chOut;
break;
}
}

return m_nOutSize;
}

// 编码 〔字符串〕
int CBase64::Encode( LPCTSTR pszEncoding, LPTSTR pszOutput, int nSize )
{
if( pszEncoding == NULL )
return (-1);

m_nInSize = nSize;
m_nOutSize = (nSize/3)*4;
m_nOutSize += (nSize%3 == 0)?0:4;

if( pszOutput == NULL)
{
pszOutput = new TCHAR[m_nOutSize];
if( pszOutput == NULL )
return (-1);
}

int nDigit,nIndex;

for( nIndex = 0 ; nIndex < m_nOutSize ; nIndex++)
{
nDigit = ReadBits( pszEncoding, nSize, nIndex );
pszOutput[nIndex] = BASE64_TAB[ nDigit ];
}
return m_nOutSize;
}

// 获取输出的长度(并不准确,用于分配足够缓冲)
int CBase64::GetOutSize( int nSize , BOOL bEncode)
{
int nOutSize;
if(bEncode)
{
nOutSize = (nSize/3)*4;
nOutSize += (nSize%3 == 0)?0:4;
}
else
nOutSize = (nSize/4)*3; // 最大长度

return nOutSize;
}
lalala 2000-05-09
  • 打赏
  • 举报
回复
有base64的编码吗?

4,354

社区成员

发帖
与我相关
我的任务
社区描述
通信技术相关讨论
社区管理员
  • 网络通信
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧