View as "text/plain" | Blame | Last modification | View Log | Download | RSS feed
/*
* Copyright 2014 Brian Rosenberger (Brutex Network)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.brutex.emitter.util;
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.salt.StringFixedSaltGenerator;
/**
* The Class PasswordEncrypter.
* @since 0.2
*/
public class PasswordEncrypter {
/** The Constant key. */
private static final String key = "sdasfAasdFsDc4ASasdXacca/&dasd";
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
if(args.length<1) {
System.out.println("No password given.");
System.exit(1);
}
final StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
enc.setPassword(key);
enc.setSaltGenerator(new StringFixedSaltGenerator(PasswordEncrypter.class.getCanonicalName()) );
String myEncryptedText = enc.encrypt(args[0]);
System.out.println("Your encrypted password is:");
System.out.println(myEncryptedText);
}
/**
* Decrypt.
*
* @param C the c
* @return the string
*/
public static String decrypt(final String C) {
final StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
enc.setPassword(key);
enc.setSaltGenerator(new StringFixedSaltGenerator(PasswordEncrypter.class.getCanonicalName()) );
return enc.decrypt(C);
}
}