MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / decryptAES

Method decryptAES

java/src/cx/fbn/encrypt/EnCrypt.java:268–314  ·  view source on GitHub ↗
(String text, String passphrase, int keylen)

Source from the content-addressed store, hash-verified

266
267 // Decrypt the base64 text and return the unsecure text
268 public String decryptAES(String text, String passphrase, int keylen) {
269 MessageDigest md;
270 try {
271
272 // Get a MD5 for the passphrase
273 md = MessageDigest.getInstance("MD5");
274 md.update(passphrase.getBytes(getCharset()));
275
276 // Setup parms for the cipher
277 byte[] digest = md.digest();
278 SecretKeySpec skeySpec = new SecretKeySpec(digest, "AES");
279 //Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
280 Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
281
282 //byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
283
284 // Needed for CBC mode
285 //IvParameterSpec ivspec = new IvParameterSpec(iv);
286 //cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivspec);
287
288 // ECB mode
289 cipher.init(Cipher.DECRYPT_MODE, skeySpec);
290
291 // Decode the encrypted text and decrypt
292 byte[] dString = Base64.decode(text);
293 byte[] d = cipher.doFinal(dString);
294
295 //String clearTextOld = decodeBytesOld(d);
296 String clearTextNew = decodeBytes(d);
297 return clearTextNew;
298 } catch (NoSuchAlgorithmException e) {
299 e.printStackTrace();
300 } catch (NoSuchPaddingException e) {
301 e.printStackTrace();
302 } catch (InvalidKeyException e) {
303 e.printStackTrace();
304 } catch (IllegalBlockSizeException e) {
305 e.printStackTrace();
306 } catch (BadPaddingException e) {
307 e.printStackTrace();
308 } catch (IOException e) {
309 e.printStackTrace();
310// } catch (InvalidAlgorithmParameterException e) {
311// e.printStackTrace();
312 }
313 return "";
314 }
315
316
317

Callers

nothing calls this directly

Calls 5

getCharsetMethod · 0.95
decodeMethod · 0.95
decodeBytesMethod · 0.95
updateMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected