otp auto picker in php

Solutions on MaxInterview for otp auto picker in php by the best coders in the world

showing results for - "otp auto picker in php"
Vincent
03 Jan 2021
1public class AppSignatureHelper extends ContextWrapper {
2  private static final String TAG = "AppSignatureHelper";
3  private static final String HASH_TYPE = "SHA-256";
4  public static final int NUM_HASHED_BYTES = 9;
5  public static final int NUM_BASE64_CHAR = 11;
6  public AppSignatureHelper(Context context) {
7    super(context);
8  }
9  /**
10   * Get the app signatures for the your current package
11   */
12  public ArrayList<String> getAppSignatures() {
13    ArrayList<String> appCodes = new ArrayList<>();
14    try {
15      // Get all package signatures for the current package
16      String packageName = getPackageName();
17      PackageManager packageManager = getPackageManager();
18      Signature[] signatures = packageManager.getPackageInfo(packageName,
19          PackageManager.GET_SIGNATURES).signatures;
20      // For each signature create a compatible hash
21      for (Signature signature : signatures) {
22        String hash = hash(packageName, signature.toCharsString());
23        if (hash != null) {
24          appCodes.add(String.format("%s", hash));
25        }
26      }
27    } catch (PackageManager.NameNotFoundException e) {
28      Log.e(TAG, "Unable to find package to obtain hash.", e);
29    }
30    return appCodes;
31  }
32  private static String hash(String packageName, String signature) {
33    String appInfo = packageName + " " + signature;
34    try {
35      MessageDigest messageDigest = MessageDigest.getInstance(HASH_TYPE);
36      messageDigest.update(appInfo.getBytes(StandardCharsets.UTF_8));
37      byte[] hashSignature = messageDigest.digest();
38      // truncated into NUM_HASHED_BYTES
39      hashSignature = Arrays.copyOfRange(hashSignature, 0, NUM_HASHED_BYTES);
40      // encode into Base64
41      String base64Hash = Base64.encodeToString(hashSignature, Base64.NO_PADDING | Base64.NO_WRAP);
42      base64Hash = base64Hash.substring(0, NUM_BASE64_CHAR);
43      Log.d(TAG, String.format("pkg: %s -- hash: %s", packageName, base64Hash));
44      return base64Hash;
45    } catch (NoSuchAlgorithmException e) {
46      Log.e(TAG, "hash:NoSuchAlgorithm", e);
47    }
48    return null;
49  }
50}
51
similar questions
queries leading to this page
otp auto picker in php