im doing a tutorial on facebook intergration with android app and it needs a haskey for it to work and generating a key hash requires to install an openssl in download one already in this link https://code.google.com/p/openssl-for-windows/downloads/detail?name=openssl-0.9.8k_WIN32.zip&can=2&q= but im not sure how to install it when i click on the openssl application it prompts a command line how do i install openssl
问问题
315 次
1 回答
1
您也可以使用此代码生成密钥哈希...
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/KeyText"
/>
</LinearLayout>
MainActivity.java
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
PackageInfo info = getPackageManager().getPackageInfo("com.key", PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
TextView tvmyName = (TextView)findViewById(R.id.KeyText);
tvmyName.setText(Base64.encodeBytes(md.digest()));
}
} catch (NameNotFoundException e) {
} catch (NoSuchAlgorithmException e) {
}
}
}
于 2013-10-11T04:31:49.800 回答