Autopsy 4.22.1
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
20package org.sleuthkit.autopsy.coreutils;
21
22import java.util.Base64;
23import javax.crypto.Cipher;
24import javax.crypto.SecretKey;
25import javax.crypto.SecretKeyFactory;
26import javax.crypto.spec.PBEKeySpec;
27import javax.crypto.spec.PBEParameterSpec;
28import org.openide.util.NbBundle;
29
33public final class TextConverter {
34
35 private static final char[] KEY = "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(KEY));
51 Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); //NON-NLS
52 pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
53 return Base64.getEncoder().encodeToString(pbeCipher.doFinal(property.getBytes("UTF-8"))); //NON-NLS
54 } catch (Exception ex) {
55 throw new TextConverterException(NbBundle.getMessage(TextConverter.class, "TextConverter.convert.exception.txt"));
56 }
57 }
58
68 public static String convertHexTextToText(String property) throws TextConverterException {
69 try {
70 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); //NON-NLS
71 SecretKey key = keyFactory.generateSecret(new PBEKeySpec(KEY));
72 Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); //NON-NLS
73 pbeCipher.init(Cipher.DECRYPT_MODE, key, new PBEParameterSpec(SALT, 20));
74 return new String(pbeCipher.doFinal(Base64.getDecoder().decode(property)), "UTF-8"); //NON-NLS
75 } catch (Exception ex) {
76 throw new TextConverterException(NbBundle.getMessage(TextConverter.class, "TextConverter.convertFromHex.exception.txt"));
77 }
78 }
79
80 private TextConverter() {
81 }
82}
static String convertHexTextToText(String property)
static String convertTextToHexText(String property)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.