创建哈希键时出错

时间:2013-07-16 05:19:06

标签: android adb

C:\Documents and Settings\Admin\ keytool -export -alias androiddebugkey -keystore "C:\Documents and Settings\Admin\.android\debug.keystore" | D:\openssl\bin\openssl.exe sha1 -binary | D:\openssl\bin\openssl.exe enc -a 

我只是运行上面的代码来生成哈希键,但它显示了一些错误......比如

The filename ,directory name,or volume label syntax is incorrect

1 个答案:

答案 0 :(得分:2)

您可以查看以下链接,了解分步教程

How to get Key Hashes for android-facebook app

如果您仍遇到同样的问题,可以使用以下代码段生成keyhash。这对我来说非常好。

PackageInfo packageInfo;
        try {
        packageInfo = getPackageManager().getPackageInfo("com.yourapp", 
PackageManager.GET_SIGNATURES);
        for (Signature signature : packageInfo.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String key = new String(Base64.encode(md.digest(), 0));
                // String key = new String(Base64.encodeBytes(md.digest()));
                Log.e("Hash key", key);
        } 
        }
        catch (NameNotFoundException e1) {
            Log.e("Name not found", e1.toString());
        }

        catch (NoSuchAlgorithmException e) {
            Log.e("No such an algorithm", e.toString());
        }
        catch (Exception e){
            Log.e("Exception", e.toString());
        }