我正在尝试在Volley JsonObjectRequest中发送POST参数.最初,它通过遵循官方代码所说的传递包含JsonObjectRequest的构造函数中的参数的JSONObject来为我工作.然后它突然停止工作,我没有对以前工作的代码进行任何更改.服务器不再识别正在发送任何POST参数.这是我的代码:
RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://myserveraddress";
// POST parameters
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "test");
JSONObject jsonObj = new JSONObject(params);
// Request a json response from the provided URL
JsonObjectRequest jsonObjRequest = new JsonObjectRequest
(Request.Method.POST, url, jsonObj, new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response)
{
Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
}
});
// Add the request to …Run Code Online (Sandbox Code Playgroud) 我正在开发一个文件加密/解密应用程序.我正在使用一个简单的.txt文件进行测试.当我从应用程序中选择文件并选择加密时,整个文件数据都会被加密.但是,当我解密时,只有部分文件数据被解密.由于某种原因,前16个字节/字符不会被解密.
test_file.txt内容: "This sentence is used to check file encryption/decryption results."
加密结果: "¾mÁSTÐÿT:Y„"O¤]ÞPÕµß~ëqrÈb×ßq²¨†ldµJ,O|56\e^-’@þûÝû"
解密结果: "£ÿÒÜÑàh]VÄþ„- used to check file encryption/decryption results."
logcat中没有任何错误.
我究竟做错了什么?
加密文件的方法:
public void encryptFile(String password, String filePath) {
byte[] encryptedFileData = null;
byte[] fileData = null;
try {
fileData = readFile(filePath);//method provided below
// 64 bit salt for testing only
byte[] salt = "goodsalt".getBytes("UTF-8");
SecretKey key = generateKey(password.toCharArray(), salt);//method provided below
byte[] keyData = key.getEncoded();
SecretKeySpec sKeySpec = new SecretKeySpec(keyData, "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, sKeySpec); …Run Code Online (Sandbox Code Playgroud)