File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/Blowfish.java | File path: /columba-1.4-src/core/src/main/java/org/columba/core/base/Blowfish.java | |||
Method name: String encrypt(char[])
|
Method name: char[] decrypt(String)
|
|||
Number of AST nodes: 7 | Number of AST nodes: 8 | |||
1 | try {↵ | 1 | try {↵ | |
2 | // Create the cipher↵ | 2 | // Create the cipher↵ | |
3 | Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$↵ | 3 | Cipher blowCipher = Cipher.getInstance("Blowfish"); //$NON-NLS-1$↵ | |
4 | // Initialize the cipher for encryption↵ | 4 | // Initialize the cipher for encryption↵ | |
5 | blowCipher.init(Cipher.ENCRYPT_MODE, KEY);↵ | 5 | blowCipher.init(Cipher.DECRYPT_MODE, KEY);↵ | |
6 | // Our cleartext as bytes↵ | 6 | // Encrypt the cleartext↵ | |
7 | ByteBuffer ciphertext = Base64.decode(source);↵ | |||
7 | byte[] cleartext = new String(source).getBytes("UTF-8"); //$NON-NLS-1$↵ | 8 | byte[] c↵ | |
8 | // Encrypt the↵ | 9 | ipherArray = new byte[ciphertext.limit()];↵ | |
10 | ciphertext.get(cipherArray);↵ | |||
9 | cleartext↵ | 11 | // Our cleartext as bytes↵ | |
10 | byte[] ciphertext = blowCipher.doFinal(cleartext);↵ | 12 | byte[] cleartext = blowCipher.doFinal(cipherArray);↵ | |
11 | // Return a String representation of the cipher text↵ | 13 | // Return a String representation of the cipher text↵ | |
12 | return Base64.encode(ByteBuffer.wrap(ciphertext)).toString();↵ | 14 | return new String(cleartext, "UTF-8").toCharArray(); //$NON-NLS-1$↵ | |
13 | } catch (InvalidKeyException e) {↵ | 15 | } catch (InvalidKeyException e) {↵ | |
14 | LOG.severe(e.toString());↵ | 16 | LOG.severe(e.toString());↵ | |
15 | } catch (NoSuchAlgorithmException e) {↵ | 17 | } catch (NoSuchAlgorithmException e) {↵ | |
16 | LOG.severe(e.toString());↵ | 18 | LOG.severe(e.toString());↵ | |
17 | } catch (NoSuchPaddingException e) {↵ | 19 | } catch (NoSuchPaddingException e) {↵ | |
18 | LOG.severe(e.toString());↵ | 20 | LOG.severe(e.toString());↵ | |
19 | } catch (UnsupportedEncodingException e) {↵ | 21 | } catch (UnsupportedEncodingException e) {↵ | |
20 | LOG.severe(e.toString());↵ | 22 | LOG.severe(e.toString());↵ | |
21 | } catch (IllegalStateException e) {↵ | 23 | } catch (IllegalStateException e) {↵ | |
22 | LOG.severe(e.toString());↵ | 24 | LOG.severe(e.toString());↵ | |
23 | } catch (IllegalBlockSizeException e) {↵ | 25 | } catch (IllegalBlockSizeException e) {↵ | |
24 | LOG.severe(e.toString());↵ | 26 | LOG.severe(e.toString());↵ | |
25 | } catch (BadPaddingException e) {↵ | 27 | } catch (BadPaddingException e) {↵ | |
26 | LOG.severe(e.toString());↵ | 28 | LOG.severe(e.toString());↵ | |
27 | }↵ | 29 |
| |
28 | return new String(); | |||
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.8 |
Clones location | Clones are declared in the same class |
Number of node comparisons | 48 |
Number of mapped statements | 5 |
Number of unmapped statements in the first code fragment | 2 |
Number of unmapped statements in the second code fragment | 3 |
Time elapsed for statement mapping (ms) | 4.1 |
Clone type | Type 3 |
ID | Statement | ID | Statement | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | try | 1 | try | ||||||||||||||||
2 | Cipher blowCipher = Cipher.getInstance("Blowfish"); | 2 | Cipher blowCipher = Cipher.getInstance("Blowfish"); | ||||||||||||||||
3 | blowCipher.init(Cipher.ENCRYPT_MODE, KEY); |
| 3 | blowCipher.init(Cipher.DECRYPT_MODE, KEY); | |||||||||||||||
| 4 | ByteBuffer ciphertext = Base64.decode(source); | |||||||||||||||||
4 | byte[] cleartext = new String(source).getBytes("UTF-8"); |
| 5 | byte[] cipherArray = new byte[ciphertext.limit()]; | |||||||||||||||
|
| 6 | ciphertext.get(cipherArray); | ||||||||||||||||
5 | byte[] ciphertext = blowCipher.doFinal(cleartext); |
| 7 | byte[] cleartext = blowCipher.doFinal(cipherArray); | |||||||||||||||
6 | return Base64.encode(ByteBuffer.wrap(ciphertext)).toString(); |
| | ||||||||||||||||
|
| 8 | return new String(cleartext, "UTF-8").toCharArray(); | ||||||||||||||||
7 | return new String(); |
| |
Row | Violation |
---|---|
1 | Expression new String(source).getBytes("UTF-8") is a method call throwing exception(s) that should be caught by a try block that will be extracted |
2 | Expression new byte[ciphertext.limit()] cannot be parameterized, because it has dependencies to/from statements that will be extracted |
3 | Unmatched statement ciphertext.get(cipherArray); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement return Base64.encode(ByteBuffer.wrap(ciphertext)).toString(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
5 | Unmatched return Base64.encode(ByteBuffer.wrap(ciphertext)).toString(); |
6 | Unmatched statement return new String(cleartext,"UTF-8").toCharArray(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
7 | Unmatched statement return new String(cleartext,"UTF-8").toCharArray(); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted |
8 | Unmatched return new String(cleartext,"UTF-8").toCharArray(); |
9 | Unmatched return new String(); |
10 | Clone fragment #1 returns variables ciphertext , while Clone fragment #2 returns variables cipherArray, cleartext |