Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *  Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
 */

import android.provider.Settings;
import android.util.Log;
import java.io.UnsupportedEncodingException;

public class Main {
    private static final String TAG = "AuthUtil";

    /**
     * Generates an encryption key for devices with API level lower than 18 using the
     * ANDROID_ID value as a seed.
     * In production scenarios, you should come up with your own implementation of this method.
     * Consider that your algorithm must return the same key so it can encrypt/decrypt values
     * successfully.
     *
     * @return The encryption key in a 32 byte long array.
     */
    private static byte[] generateSecretKey() {
        byte[] key = new byte[32];
        byte[] android_id = null;

        try {
            android_id = Settings.Secure.ANDROID_ID.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            Log.e(TAG, "generateSecretKey - " + e.getMessage());
        }

        for (int i = 0; i < key.length; i++) {
            key[i] = android_id[i % android_id.length];
        }

        return key;
    }
}