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

Method decryptRC2

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

Source from the content-addressed store, hash-verified

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

Callers 1

mainMethod · 0.95

Calls 5

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

Tested by

no test coverage detected