package ru.bvn13.encryptedpreferences; import java.security.*; import javax.crypto.*; import javax.crypto.spec.*; /** * Created by bvn13 on 22.06.2017. */ public class EncryptionStuff { static private final String algorithm = "DES"; static private SecureRandom sr = new SecureRandom(); private SecretKey secretKey; private Cipher cipher; public EncryptionStuff( SecretKey secretKey ) throws GeneralSecurityException { this.secretKey = secretKey; cipher = Cipher.getInstance( algorithm ); } public String arrayToString( byte raw[] ) { StringBuffer sb = new StringBuffer(); for (int i=0; i0) s += 256; int hi = s>>4; int lo = s&0xf; sb.append( (char)('a'+hi) ); sb.append( (char)('a'+lo) ); } return sb.toString(); } public byte[] stringToArray( String string ) { StringBuffer sb = new StringBuffer( string ); int len = sb.length(); if ((len&1)==1) throw new RuntimeException( "String must be of even length! "+string ); byte raw[] = new byte[len/2]; int ii=0; for (int i=0; i