沒搞過VB 現在給我一串VB中的base64編碼,移植到Android中,按照我的想法寫好之後,發現編碼之後的結果並不一樣,請大家給我看看。
VB:
Set m_oXMLElement = m_oXMLDoc.createElement("TmpBase64")
m_oXMLElement.dataType = "bin.base64"
Public Function Encode(ByVal strIn As String) As String
Dim oElement As Object
Dim aData() As Byte
On Error GoTo errEncode:
If m_bXMLObjectOK And Len(strIn) > 0 Then
aData = StrConv(strIn, vbFromUnicode) '將Unicode編碼轉換為系統缺省碼頁
m_oXMLElement.nodetypedvalue = aData
Encode = m_oXMLElement.Text
m_oXMLElement.Text = ""
End If
Exit Function
errEncode:
RaiseError Err.Number, Err.Description
End Function
Android:
public String encode (){
String test = testText.getText().toString();//從TextView控件中取得字符串
String code = Base64.encodeToString(name.getBytes(), Base64.NO_WRAP);
TEST_CODE = code;
return TEST_CODE;
兩個測試中文,返回的結果不一樣。
解決了。
byte[] testCode= null;
try {
testCode = Base64.encode(test.trim().getBytes("GB2312"), Base64.NO_WRAP);
Test_CODE = new String(testcode, "GB2312");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return Text_CODE ;