If you think the Android project myglob listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* MyGlob Android Application//fromwww.java2s.com
*
* Copyright (C) 2010 Petar Petrov
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/package net.vexelon.myglob.crypto;
import net.vexelon.myglob.utils.Base64;
publicclass PasswordEngineImpl1 implements PasswordEngine {
privatestatic PasswordEngineImpl1 _INSTANCE = null;
//128 bit key
privatefinalstaticbyte[] iv = { 0x28, 0x1A, 0x03, 0x78, 0x4F, 0x12, 0x62, 0x04, 0x55, 0x07, 0x3A, 0x6F, 0x1B, 0x12, 0x0B, 0x01 };
private Crypto _crypto;
privatebyte[] _key;
publicstatic PasswordEngineImpl1 getInstance(String encodedKey) throws Exception {
if (_INSTANCE == null)
_INSTANCE = new PasswordEngineImpl1(encodedKey);
return _INSTANCE;
}
private PasswordEngineImpl1(String encodedKey) throws Exception {
_crypto = CryptoAES.getInstance();
_key = Base64.decode(encodedKey);
}
@Override
public String encryptAndEncode(String rawPassword) throws Exception {
byte[] encrypted = _crypto.encrypt(rawPassword.getBytes(), _key, iv);
return Base64.encodeBytes(encrypted);
}
@Override
public String decodeAndDecrypt(String encodedPassword) throws Exception {
byte[] decrypted = _crypto.decrypt(Base64.decode(encodedPassword), _key, iv);
returnnew String(decrypted);
}
}