View Javadoc

1   /**
2    * Copyright 2009-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 org.codehaus.mojo.properties;
17  
18  import org.apache.maven.plugin.AbstractMojo;
19  import org.apache.maven.plugin.MojoExecutionException;
20  import org.jasypt.util.text.BasicTextEncryptor;
21  
22  /**
23   * Encrypt the specified text using the specified password
24   *
25   * @goal encrypt
26   */
27  public class EncryptMojo extends AbstractMojo {
28  
29      /**
30       *
31       * The password for encrypting text. This same password can be used to to decrypt the encrypted text
32       *
33       * @parameter expression="${crypto.password}"
34       * @required
35       */
36      private String password;
37  
38      /**
39       *
40       * The text to encrypt.
41       *
42       * @parameter expression="${crypto.text}"
43       * @required
44       */
45      private String text;
46  
47      @Override
48      public void execute() throws MojoExecutionException {
49          BasicTextEncryptor encryptor = new BasicTextEncryptor();
50          encryptor.setPassword(password);
51          String encrypted = encryptor.encrypt(text);
52          getLog().info(text + " -> " + encrypted);
53      }
54  
55  }