Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
TextConverter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 package org.sleuthkit.autopsy.coreutils;
21 
22 import java.util.Base64;
23 import javax.crypto.Cipher;
24 import javax.crypto.SecretKey;
25 import javax.crypto.SecretKeyFactory;
26 import javax.crypto.spec.PBEKeySpec;
27 import javax.crypto.spec.PBEParameterSpec;
28 import org.openide.util.NbBundle;
29 
33 public final class TextConverter {
34 
35  private static final char[] TMP = "hgleri21auty84fwe".toCharArray(); //NON-NLS
36  private static final byte[] SALT = {(byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12};
37 
47  public static String convertTextToHexText(String property) throws TextConverterException {
48  try {
49  SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); //NON-NLS
50  SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP));
51  Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); //NON-NLS
52  pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
53  return base64Encode(pbeCipher.doFinal(property.getBytes("UTF-8")));
54  } catch (Exception ex) {
55  throw new TextConverterException(NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt"));
56  }
57  }
58 
59  public static String base64Encode(byte[] bytes) {
60  return Base64.getEncoder().encodeToString(bytes);
61  }
62 
72  public static String convertHexTextToText(String property) throws TextConverterException {
73  try {
74  SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); //NON-NLS
75  SecretKey key = keyFactory.generateSecret(new PBEKeySpec(TMP));
76  Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); //NON-NLS
77  pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
78  return new String(pbeCipher.doFinal(base64Decode(property)), "UTF-8");
79  } catch (Exception ex) {
80  throw new TextConverterException(NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt"));
81  }
82  }
83 
84  public static byte[] base64Decode(String property) {
85  return Base64.getDecoder().decode(property);
86  }
87 
88 }
static byte[] base64Decode(String property)
static String convertTextToHexText(String property)
static String convertHexTextToText(String property)

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.