read Key Spec - Android java.security

Android examples for java.security:Key

Description

read Key Spec

Demo Code


import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import android.content.Context;

public class Main{
    private final static String SECRET_KEY = "secret.key";
    private static Logger logger = Logger.getLogger(CryptoUtil.class
            .getPackage().getName());//from  w w  w . j  a va 2 s. c o m
    private static SecretKeySpec readKeySpec(final Context context) {
        SecretKeySpec keySpec = null;
        try {
            FileInputStream fileStream = context.openFileInput(SECRET_KEY);
            ObjectInputStream objectStream = new ObjectInputStream(
                    fileStream);
            keySpec = (SecretKeySpec) objectStream.readObject();
        } catch (Exception e) {
            logger.log(
                    Level.INFO,
                    "CryptoUtil#readKeySpec exception: "
                            + e.getLocalizedMessage());
        }
        return keySpec;
    }
}

Related Tutorials