Example usage for android.content.pm Signature toByteArray

List of usage examples for android.content.pm Signature toByteArray

Introduction

In this page you can find the example usage for android.content.pm Signature toByteArray.

Prototype

public byte[] toByteArray() 

Source Link

Usage

From source file:com.facebook.unity.FB.java

/**
 * Provides the key hash to solve the openSSL issue with Amazon
 * @return key hash/* w w  w  .jav a2s  .co m*/
 */
@TargetApi(Build.VERSION_CODES.FROYO)
public static String getKeyHash() {
    try {
        // In some cases the unity activity may not exist. This can happen when we are
        // completing a login and unity activity was killed in the background. In this
        // situation it's not necessary to send back the keyhash since the app will overwrite
        // the value with the value they get during the init call and the unity activity
        // wil be created by the time init is called.
        Activity activity = getUnityActivity();
        if (activity == null) {
            return "";
        }

        PackageInfo info = activity.getPackageManager().getPackageInfo(activity.getPackageName(),
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            String keyHash = Base64.encodeToString(md.digest(), Base64.DEFAULT);
            Log.d(TAG, "KeyHash: " + keyHash);
            return keyHash;
        }
    } catch (NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }
    return "";
}

From source file:br.com.hotforms.FacebookHash.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArry of arguments for the plugin.
 * @param callbackContext   The callback id used when calling back into JavaScript.
 * @return                  True if the action was valid, false otherwise.
 *//* w w w  .  j av a 2  s .  c o  m*/
@Override
public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext)
        throws JSONException {
    Log.v(TAG, "Executing action: " + action);
    final Activity activity = this.cordova.getActivity();
    final Window window = activity.getWindow();

    if ("getHash".equals(action)) {
        try {
            String packageName = activity.getClass().getPackage().getName();
            PackageManager packageManager = activity.getPackageManager();
            PackageInfo info = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                String hash = Base64.encodeToString(md.digest(), Base64.DEFAULT);

                String result = String.format("{ FacebookHash : \"%s\", PackageName : \"%s\"}", hash.trim(),
                        packageName);
                callbackContext.success(result);
            }
        } catch (NameNotFoundException e) {
            callbackContext.error(e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            callbackContext.error(e.getMessage());
        }
        return true;
    }

    return false;
}

From source file:com.ibm.mobileclientaccess.fbauth.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    infoTextView = (TextView) findViewById(R.id.info);

    MCAAuthorizationManager.createInstance(this);

    Logger.setSDKDebugLoggingEnabled(true);

    /*/*from   w ww  . j a  v a 2 s. c  o  m*/
    There may be issues with the hash key for the app, because it may not be correct when using from command line
    https://developers.facebook.com/docs/android/getting-started#release-key-hash (troubleshoot section)
    Add this code (and remove after getting the correct key (debug? release)) for this will print to log the correct hash code.
     */
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
    } catch (NoSuchAlgorithmException e) {
    }

    try {
        //Register to the server with backendroute and GUID
        BMSClient.getInstance().initialize(this, backendRoute, backendGUID, BMSClient.REGION_UK);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }

    // Register the default delegate for Facebook
    FacebookAuthenticationManager.getInstance().register(this);
    Logger.setSDKDebugLoggingEnabled(true);
}

From source file:com.hkm.Application.appWork.java

private void showpackagesigning() {
    PackageInfo packageInfo;/* w w w. j  a v  a  2s.  c om*/
    try {
        packageInfo = getPackageManager().getPackageInfo("com.hkm.oc.app", 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", sha1Hash(key));
        }
    } catch (PackageManager.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());
    }
}

From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);//from   ww  w.  j  a v  a2s. c  o m
    Log.v("msg", "hello");
    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.facebook.samples.sessionlogin",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    buttonLoginLogout = (Button) findViewById(R.id.buttonLoginLogout);
    textInstructionsOrLink = (TextView) findViewById(R.id.instructionsOrLink);

    Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

    Session session = Session.getActiveSession();
    if (session == null) {
        if (savedInstanceState != null) {
            session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
        }
        if (session == null) {
            session = new Session(this);
        }
        Session.setActiveSession(session);
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }
    Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(this,
            Arrays.asList("friends_birthday"));
    session.requestNewReadPermissions(newPermissionsRequest);
    updateView();
}

From source file:com.facebook.samples.hellofacebook.MapFriends.java

private void getKeyHash() {
    try {/*from  w ww  .  jav  a2s .  com*/
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
        Log.d("getKeyHash()", "NameNotFoundException");
    } catch (NoSuchAlgorithmException e) {
        Log.d("getKeyHash()", "NoSuchAlgorithmException");
    }
}

From source file:com.pseudosudostudios.jdd.activities.WinActivity.java

private void printFacebookInfo() {
    if (!isUserDebuggable())
        return;/*from  ww  w .j av a2 s  . c om*/
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

}

From source file:com.smashedin.facebook.HelloFacebookSampleActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    try {//  w w w.  ja va2s  . com
        PackageInfo info = getPackageManager().getPackageInfo("com.smashedin.smashedin",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            HelloFacebookSampleActivity.this.user = user;
            updateUI();
        }
    });
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey(EXTRA_ACCOUNTNAME)) {
        mEmail = extras.getString(EXTRA_ACCOUNTNAME);
        getTask(HelloFacebookSampleActivity.this, mEmail, SCOPE).execute();
    }
    /*
    LinearLayout nevermind = (LinearLayout) findViewById(R.id.nevermind);
    nevermind.setOnClickListener(new OnClickListener() {
             
     @Override
     public void onClick(View arg0) {
            
    Singleton.getInstance().m_bnevermind = true;
    finish();
     }
    });
    */
}

From source file:fe.up.pt.partner.FacebookActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    Bundle b = getIntent().getExtras();//from w  w w.  j  a va2s .co m
    title = b.getString("title");
    author = b.getString("author");
    rating = b.getString("rating");

    /*
     * este bloco  para imprimir a ash para depois se colocar no
     * site da app no facebook 
    */
    try {
        PackageInfo info = getPackageManager().getPackageInfo("fe.up.pt.partner",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    if (savedInstanceState != null) {
        String name = savedInstanceState.getString(PENDING_ACTION_BUNDLE_KEY);
        pendingAction = PendingAction.valueOf(name);
    }

    setContentView(R.layout.main);

    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setUserInfoChangedCallback(new LoginButton.UserInfoChangedCallback() {
        @Override
        public void onUserInfoFetched(GraphUser user) {
            FacebookActivity.this.user = user;
            updateUI();
            // It's possible that we were waiting for this.user to be populated in order to post a
            // status update.
            handlePendingAction();

        }
    });

    profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
    text_box = (EditText) findViewById(R.id.share_text);
    postStatusUpdateButton = (Button) findViewById(R.id.postStatusUpdateButton);
    cancelButton = (Button) findViewById(R.id.cancel_button);

    postStatusUpdateButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            onClickPostStatusUpdate();

        }
    });
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            finish();

        }
    });

    controlsContainer = (ViewGroup) findViewById(R.id.main_ui_container);

    final FragmentManager fm = getSupportFragmentManager();

    // Listen for changes in the back stack so we know if a fragment got popped off because the user
    // clicked the back button.
    fm.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
        @Override
        public void onBackStackChanged() {
            if (fm.getBackStackEntryCount() == 0) {
                // We need to re-show our UI.
                controlsContainer.setVisibility(View.VISIBLE);
            }
        }
    });
}

From source file:com.igames2go.t4f.Activities.LoginPage.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mApplication = ((T4FApplication) getApplication());
    mApplication.setPlay_mode(T4FApplication.PLAY_MODE_LOGIN);
    try {//w w  w. j a  v  a  2s.c  o m
        PackageInfo info = getPackageManager().getPackageInfo("com.igames2go.t4f",
                PackageManager.GET_SIGNATURES);
        for (android.content.pm.Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.d("KeyHash:====================", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (NameNotFoundException e) {

    } catch (NoSuchAlgorithmException e) {

    }

    setContentView(R.layout.main);

    pref = getSharedPreferences("user_info", MODE_PRIVATE);

    mApplication = (T4FApplication) getApplication();
    app_id = getResources().getString(R.string.appid);

    inputEmail = (EditText) findViewById(R.id.emailText);
    inputPassword = (EditText) findViewById(R.id.passwordText);
    btnLogin = (ImageButton) findViewById(R.id.loginButton);
    btnSignUp = (ImageButton) findViewById(R.id.signupButton);
    btnForgot = (ImageButton) findViewById(R.id.forgotButton);
    btnNoLoginPlay = (ImageButton) findViewById(R.id.noLoginPlayButton);
    btnHowToPlay = (ImageButton) findViewById(R.id.howToPlayButton);
    btnHelp = (ImageButton) findViewById(R.id.helpButton);
    //loginErrorMsg = (TextView) findViewById(R.id.loginErrorMsg);

    inputEmail.setText(pref.getString("user_email", ""));
    inputPassword.setText(pref.getString("user_password", ""));

    btnLogin.setOnClickListener(this);
    btnSignUp.setOnClickListener(this);
    btnForgot.setOnClickListener(this);
    btnNoLoginPlay.setOnClickListener(this);
    btnHowToPlay.setOnClickListener(this);
    btnHelp.setOnClickListener(this);
}