170 |
brianR |
1 |
/*
|
|
|
2 |
* Copyright 2014 Brian Rosenberger (Brutex Network)
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
package net.brutex.emitter.util;
|
|
|
17 |
|
|
|
18 |
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
|
|
|
19 |
import org.jasypt.salt.StringFixedSaltGenerator;
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* The Class PasswordEncrypter.
|
|
|
24 |
* @since 0.2
|
|
|
25 |
*/
|
|
|
26 |
public class PasswordEncrypter {
|
|
|
27 |
|
|
|
28 |
/** The Constant key. */
|
|
|
29 |
private static final String key = "sdasfAasdFsDc4ASasdXacca/&dasd";
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
* The main method.
|
|
|
33 |
*
|
|
|
34 |
* @param args the arguments
|
|
|
35 |
*/
|
|
|
36 |
public static void main(String[] args) {
|
|
|
37 |
if(args.length<1) {
|
|
|
38 |
System.out.println("No password given.");
|
|
|
39 |
System.exit(1);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
final StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
|
|
|
43 |
enc.setPassword(key);
|
|
|
44 |
enc.setSaltGenerator(new StringFixedSaltGenerator(PasswordEncrypter.class.getCanonicalName()) );
|
|
|
45 |
|
|
|
46 |
String myEncryptedText = enc.encrypt(args[0]);
|
|
|
47 |
System.out.println("Your encrypted password is:");
|
|
|
48 |
System.out.println(myEncryptedText);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Decrypt.
|
|
|
53 |
*
|
|
|
54 |
* @param C the c
|
|
|
55 |
* @return the string
|
|
|
56 |
*/
|
|
|
57 |
public static String decrypt(final String C) {
|
|
|
58 |
final StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
|
|
|
59 |
enc.setPassword(key);
|
|
|
60 |
enc.setSaltGenerator(new StringFixedSaltGenerator(PasswordEncrypter.class.getCanonicalName()) );
|
|
|
61 |
|
|
|
62 |
return enc.decrypt(C);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
}
|