(String text, String passphrase, int keylen)
| 186 | |
| 187 | // Decrypt the base64 text and return the unsecure text |
| 188 | public String decryptRC2(String text, String passphrase, int keylen) { |
| 189 | RC2ParameterSpec parm = new RC2ParameterSpec(keylen); |
| 190 | MessageDigest md; |
| 191 | try { |
| 192 | // Get a MD5 for the passphrase |
| 193 | md = MessageDigest.getInstance("MD5"); |
| 194 | md.update(passphrase.getBytes(getCharset())); |
| 195 | |
| 196 | // Setup parms for the cipher |
| 197 | SecretKeySpec skeySpec = new SecretKeySpec(md.digest(), "RC2"); |
| 198 | Cipher cipher = Cipher.getInstance("RC2/ECB/NOPADDING"); |
| 199 | cipher.init(Cipher.DECRYPT_MODE, skeySpec, parm); |
| 200 | |
| 201 | // Decode the encrypted text and decrypt |
| 202 | byte[] dString = Base64.decode(text); |
| 203 | byte[] d = cipher.doFinal(dString); |
| 204 | |
| 205 | //String clearTextOld = decodeBytesOld(d); |
| 206 | String clearTextNew = decodeBytes(d); |
| 207 | return clearTextNew; |
| 208 | } catch (NoSuchAlgorithmException e) { |
| 209 | e.printStackTrace(); |
| 210 | } catch (NoSuchPaddingException e) { |
| 211 | e.printStackTrace(); |
| 212 | } catch (InvalidKeyException e) { |
| 213 | e.printStackTrace(); |
| 214 | } catch (InvalidAlgorithmParameterException e) { |
| 215 | e.printStackTrace(); |
| 216 | } catch (IllegalBlockSizeException e) { |
| 217 | e.printStackTrace(); |
| 218 | } catch (BadPaddingException e) { |
| 219 | e.printStackTrace(); |
| 220 | } catch (IOException e) { |
| 221 | e.printStackTrace(); |
| 222 | } |
| 223 | return ""; |
| 224 | } |
| 225 | |
| 226 | |
| 227 |
no test coverage detected