Android Password Encrypt encryptionKey(String password)

Here you can find the source of encryptionKey(String password)

Description

encryption Key

Declaration

public static String encryptionKey(String password) 

Method Source Code

//package com.java2s;

public class Main {
    private static String key2 = "1234567890-";
    private static String key1 = "13245";

    public static String encryptionKey(String password) {
        byte[] keyByte1 = key1.getBytes();
        byte[] keyByte2 = key2.getBytes();
        byte[] pwdByte = password.getBytes();
        for (int i = 0; i < pwdByte.length; i++) {
            pwdByte[i] = (byte) (pwdByte[i] ^ keyByte1[i % keyByte1.length]);
        }//from   w  w w . j av a 2 s.com
        byte[] countByte = new byte[pwdByte.length + keyByte1.length];
        for (int i = 0; i < countByte.length; i++) {
            if (i < pwdByte.length)
                countByte[i] = pwdByte[i];
            else
                countByte[i] = keyByte1[i - pwdByte.length];
        }
        for (int i = 0; i < countByte.length; i++) {
            countByte[i] = (byte) (countByte[i] ^ keyByte2[i
                    % keyByte2.length]);
        }
        return bytesToHexString(countByte);
    }

    public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
    }
}

Related

  1. encrypt(String password, String data)
  2. encryptionKey(String password)