001/** 002 * Copyright 2010-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.common.util.encrypt.jasypt; 017 018import static org.kuali.common.util.encrypt.EncryptionStrength.DEFAULT_ENCRYPTION_STRENGTH; 019import static org.kuali.common.util.encrypt.jasypt.Jasypt.buildTextEncryptor; 020 021import org.jasypt.util.text.TextEncryptor; 022import org.kuali.common.util.encrypt.EncryptionContext; 023import org.kuali.common.util.encrypt.EncryptionStrength; 024import org.kuali.common.util.encrypt.Encryptor; 025 026public final class DefaultJasyptEncryptor implements Encryptor { 027 028 public DefaultJasyptEncryptor(String password) { 029 this(password, DEFAULT_ENCRYPTION_STRENGTH); 030 } 031 032 public DefaultJasyptEncryptor(String password, EncryptionStrength strength) { 033 this(new EncryptionContext(password, strength)); 034 } 035 036 public DefaultJasyptEncryptor(EncryptionContext context) { 037 this.encryptor = buildTextEncryptor(context.getPassword(), context.getStrength()); 038 } 039 040 private final TextEncryptor encryptor; 041 042 @Override 043 public String encrypt(String text) { 044 return encryptor.encrypt(text); 045 } 046 047 @Override 048 public String decrypt(String text) { 049 return encryptor.decrypt(text); 050 } 051 052}