use of javax.crypto.spec.PBEParameterSpec in project browsermator by pcalkins.
the class Protector method encrypt.
public static String encrypt(String property) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(PASSWORD));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8")));
}
use of javax.crypto.spec.PBEParameterSpec in project wechat by dllwh.
the class PasswordUtil method decrypt.
/**
* @方法描述: 解密密文字符串
* @创建者: 皇族灬战狼
* @创建时间: 2016年5月23日 下午6:48:45
* @param ciphertext
* 待解密的密文字符串
* @param password
* 生成密钥时所使用的密码(如需解密,该参数需要与加密时使用的一致)
* @param salt
* 盐值(如需解密,该参数需要与加密时使用的一致)
* @return 解密后的明文字符串
*/
public static String decrypt(String ciphertext, String password) {
Key key = getPBEKey(password);
byte[] passDec = null;
PBEParameterSpec parameterSpec = new PBEParameterSpec(getStaticSalt(), ITERATIONCOUNT);
try {
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, key, parameterSpec);
passDec = cipher.doFinal(hexStringToBytes(ciphertext));
} catch (Exception e) {
e.printStackTrace();
}
return new String(passDec);
}
use of javax.crypto.spec.PBEParameterSpec in project ButterRemote-Android by se-bastiaan.
the class ObscuredSharedPreferences method encrypt.
protected String encrypt(String value) {
try {
final byte[] bytes = value != null ? value.getBytes(UTF8) : new byte[0];
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(PBE_WITH_MD5_AND_DES);
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(SEKRIT));
Cipher pbeCipher = Cipher.getInstance(PBE_WITH_MD5_AND_DES);
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.getString(context.getContentResolver(), Settings.System.ANDROID_ID).getBytes(UTF8), 20));
return new String(Base64.encode(pbeCipher.doFinal(bytes), Base64.NO_WRAP), UTF8);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.crypto.spec.PBEParameterSpec in project ha-bridge by bwssytems.
the class BridgeSecurity method encrypt.
static String encrypt(String property) throws GeneralSecurityException, UnsupportedEncodingException {
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFactory.generateSecret(new PBEKeySpec(habridgeKey));
Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8")));
}
use of javax.crypto.spec.PBEParameterSpec in project yyl_example by Relucent.
the class PbeWithMd5AndDesExample method decrypt.
/**
* 将加密文本进行解密
* @param encryptText String
* @return String
*/
public String decrypt(String encryptText) throws Exception {
if (encryptText == null || encryptText.length() == 0) {
return "";
}
PBEKeySpec pbks = new PBEKeySpec((password).toCharArray());
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey k = skf.generateSecret(pbks);
StringTokenizer st = new StringTokenizer(hex2string(encryptText), " ");
int num = 0;
byte[] salt = new byte[8];
while (st.hasMoreTokens() && (num < 8)) {
salt[num] = (byte) (Integer.parseInt(st.nextToken()));
num++;
}
int count = 0;
byte[] cbtemp = new byte[2000];
while (st.hasMoreTokens()) {
cbtemp[count] = (byte) (Integer.parseInt(st.nextToken()));
count++;
}
byte[] cb = new byte[count];
for (int i = 0; i < cb.length; i++) {
cb[i] = cbtemp[i];
}
Cipher cp = Cipher.getInstance("PBEWithMD5AndDES");
PBEParameterSpec ps = new PBEParameterSpec(salt, 1000);
cp.init(Cipher.DECRYPT_MODE, k, ps);
byte[] ptext = cp.doFinal(cb);
return new String(ptext, encoding);
}
Aggregations