1 19 20 package net.sourceforge.jcetaglib.taglib.crypto; 21 22 import net.sourceforge.jcetaglib.lib.Clean; 23 import net.sourceforge.jcetaglib.lib.Crypt; 24 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 59 public class FileEncrypt extends TagSupport { 60 private static final String ENCRYPT = "encrypt"; 61 62 private String file; private String newfile; 65 private String algorithm = "AES"; private String mode = "CBC"; private String padding = "PKCS7Padding"; private String keyfile; private StringBuffer passphrase; 71 private String action = "ENCRYPT"; 73 public int doStartTag() throws JspException { 74 75 try { 77 if (ENCRYPT.equalsIgnoreCase(action)) 78 Crypt.encryptFile(file, newfile, keyfile, passphrase, algorithm, mode, padding, null); 79 else 80 Crypt.encryptFile(file, newfile, keyfile, passphrase, algorithm, mode, padding, null); 81 } catch (Exception e) { 82 throw new JspException ("JCE Exception: " + e.getMessage(), e); 83 } 84 85 return SKIP_BODY; 86 } 88 public void release() { 89 Clean.blank(passphrase); 91 92 super.release(); 93 } 95 102 public void setAlgorithm(String algorithm) { 103 this.algorithm = algorithm; 104 } 105 106 113 public void setMode(String mode) { 114 this.mode = mode; 115 } 116 117 124 public void setPadding(String padding) { 125 this.padding = padding; 126 } 127 128 135 public void setKeyfile(String keyfile) { 136 this.keyfile = keyfile; 137 } 138 139 146 public void setPassphrase(StringBuffer passphrase) { 147 this.passphrase = passphrase; 148 } 149 150 157 public void setAction(String action) { 158 this.action = action; 159 } 160 161 168 public void setFile(String file) { 169 this.file = file; 170 } 171 172 179 public void setNewfile(String newfile) { 180 this.newfile = newfile; 181 } 182 } | Popular Tags |