如何加密/解密public/private。加密/解密public/private android
我假設這意味着密鑰是動態的,對於一個字符串來說永遠不會相同。
我想知道是否有任何圖書館這樣做或一步一步的教程,讓初學者理解和實施的應用程序。
我想在HTTP例如,以確保密碼:
http://www.example.com/username="ENCRYPTED1"+Password="ENCRYPTED2"
加密1和2是動態的,永遠不會相同。
通過上面的方法和密鑰應該總是改變,因此即使您在瀏覽器中鍵入加密密鑰它不應該允許,因爲密鑰會改變。
我希望這是正確的道路。
我看着Spongy城堡,我不明白如何實現它。
請幫我指導一下。
在此先感謝。
代碼:
public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://example.com/getmsgs/userno=123";
// XML node keys
static final String KEY_SONG = "song"; // parent node
static final String KEY_ID = "id";
static final String KEY_TITLE = "title";
static final String KEY_ARTIST = "artist";
static final String KEY_DURATION = "duration";
static final String KEY_THUMB_URL = "thumb_url";
ListView list;
LazyAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();
JSONObject json = JSONfunctions.getJSONfromURL(URL);
try {
JSONObject arr2 = json.getJSONObject("feed");
JSONArray arr = arr2.getJSONArray("entry");
for (int i = 0; i < arr.length(); i++) {
JSONObject e1 = arr.getJSONObject(i);
JSONArray arr3 = e1.getJSONArray("im:image");
JSONObject arr8 = e1.getJSONObject("im:name");
JSONObject arr10 = e1.getJSONObject("im:artist");
JSONObject e12 = arr3.getJSONObject(0);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
map.put(KEY_THUMB_URL, e12.getString("label"));
map.put(KEY_ARTIST, arr8.getString("label"));
map.put(KEY_TITLE, arr10.getString("label"));
// adding HashList to ArrayList
songsList.add(map);
}
} catch (JSONException e) {
// Log.e("log_tag", "Error parsing data "+e.toString());
Toast.makeText(getBaseContext(),
"Network communication error!", 5).show();
}
list=(ListView)findViewById(R.id.list);
// Getting adapter by passing xml data ArrayList
adapter=new LazyAdapter(this, songsList);
list.setAdapter(adapter);
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
HashMap<String, String> o = (HashMap<String, String>) list.getItemAtPosition(position);
Toast.makeText(CustomizedListView.this, "ID '" + o.get("KEY_TITLE") + "' was clicked.", Toast.LENGTH_SHORT).show();
}
});
}
}
PHP代碼:
<?php
$strno=$_GET['strno'];
if (isset($strno))
{
$connect=mysql_connect("localhost","test","test") or die ('Connection error!!!');
mysql_select_db("test") or die ('Database error!!!');
$query=mysql_query("select sno FROM users where strno='$strno';");
while($row = mysql_fetch_assoc($query))
{
$jsonoutput='{"json":{
"msg_sub":"'.$row['msg_sub'].'",
}}';
}
}
echo trim($jsonoutput);
mysql_close($connect) or die ('Unable to close connection-error!!!');
}
?>
JSONfunctions.java
public class JSONfunctions {
public static JSONObject getJSONfromURL(String url){
InputStream is = null;
String result = "";
JSONObject jArray = null;
//http post
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.w("log_tag", "Error converting result "+e.toString());
}
try{
jArray = new JSONObject(result);
}catch(JSONException e){
Log.w("log_tag", "Error parsing data "+e.toString());
}
return jArray;
}
}
謝謝您的回覆。我正在使用jsonFunctions。Java解析數據和代碼看起來像** JsonObject obj = jsonFunction.getjsonfromurl(「http://www.example.com/username=」ENCRYPTED1「+密碼=」ENCRYPTED2「); **目前這是我的代碼在Android中。我想動態加密它,也沒有會話在我的PHP(我希望這是正常的)。我想知道在哪裏繼續或我需要閱讀什麼來實現所需的。目前我很難過,不知道從哪裏開始。任何正確的道路上的指導將幫助我很多。再次感謝。 – 2013-04-25 05:32:19
@JamesPatrick嘿,你在這裏指出,你正在使用'JSON'.so嘗試發送你的數據在'JSON對象'''HTTP POST''中,這樣就可以對你的數據進行編碼以及'POST'將會隱藏你的參數,所以不用擔心這一點 – 2013-04-25 05:37:49
我已經添加了上面的代碼,在這裏我想加密userno即:** 123 ** – 2013-04-25 05:42:46