gpt4 book ai didi

android:加密异常

转载 作者:行者123 更新时间:2023-11-30 04:26:27 25 4
gpt4 key购买 nike

我正在制作一个应用程序,我必须在其中加密数据并将其发送到服务器,在这种情况下,当将数据转换为 int 形式时,我遇到数字格式异常。我的代码如下:

 public String encryptData(String key, String s)
{
try{
System.out.println("encrypt");
// byte[] utf8 = data.getBytes("UTF8");
byte[] fin=s.getBytes();
System.out.println("encrypt2");
// byte[] enc = ecipher.doFinal(fin);
System.out.println("encrypt3");
}catch (Exception e) {
System.out.println(e);
}
System.out.println("1");
int keyLen = key.length();
// int dataLen = Convert.ToInt16(data.length());
System.out.println("2");
Integer dataLen=Integer.parseInt(s); // **This line is giving exception**
System.out.println("3");
char chData;
char chKey;
char[] data1 = s.toCharArray();
char[] key1 = key.toCharArray();
System.out.println("4");
StringBuilder encryptedData = new StringBuilder();
for (int i = 0; i < dataLen; i++)
{
chData = data1[i];
for (int j = 0; j < keyLen; j++)
{
chKey = key1[j];
chData = (char)(chData ^ chKey);
}
encryptedData.append(chData);
}
return (encryptedData.toString());
}

我的 xml 是:

xml="<?xml version='1.0' encoding='utf-8'?>" + "<admin_auth_req><user_name>" +username+ "</user_name>" + "<password>" +PWOrd+ "</password></admin_auth_req>";

异常(exception)是:

java.lang.NumberFormatException: unable to parse '<?xml version='1.0' encoding='utf-8'?><admin_auth_req><user_name>newuser</user_name><password>tester</password></admin_auth_req>' as integer


`

最佳答案

您正在尝试将不是数字表示形式的 String 值转换为 String。您真正应该做的是找到 String 的长度。所以改变这一行:

Integer dataLen=Integer.parseInt(s);

到:

int dataLen = s.length();

关于android:加密异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8415358/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com