/* * Copyright (C) 2015 AChep@xda <artemchep@gmail.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package com.achep.base.utils; import android.support.annotation.NonNull; import android.util.Base64; /** * @author Artem Chepurnoy */ public class EncryptionUtils { /** * Method deciphers previously ciphered message * * @param message ciphered message * @param salt salt which was used for ciphering * @return deciphered message */ @NonNull public static String fromX(@NonNull String message, @NonNull String salt) throws IllegalArgumentException { return x(new String(Base64.decode(message, Base64.URL_SAFE)), salt); } /** * Symmetric algorithm used for ciphering/deciphering. * * @param message message * @param salt salt * @return ciphered/deciphered message */ @NonNull public static String x(@NonNull String message, @NonNull String salt) { final char[] m = message.toCharArray(); final char[] s = salt.toCharArray(); final int ml = m.length; final int sl = s.length; final char[] result = new char[ml]; for (int i = 0; i < ml; i++) { result[i] = (char) (m[i] ^ s[i % sl]); } return new String(result); } }