1 19 20 package net.sourceforge.jcetaglib.taglib.crypto; 21 22 import net.sourceforge.jcetaglib.lib.Clean; 23 import net.sourceforge.jcetaglib.lib.PBECrypt; 24 25 import javax.servlet.jsp.JspException ; 26 import javax.servlet.jsp.tagext.TagSupport ; 27 28 57 public class PBEFileEncrypt extends TagSupport { 58 private static final String ENCRYPT = "encrypt"; 59 60 private StringBuffer passphrase; private String algorithm = "PBEWithSHAAndIDEA-CBC"; private String seed; 64 private String action = "ENCRYPT"; 66 private String file; private String newfile; 69 public int doStartTag() throws JspException { 70 71 try { 73 if (ENCRYPT.equalsIgnoreCase(action)) 74 if (seed == null) { 75 PBECrypt.encryptFile(file, newfile, passphrase, null, algorithm); 76 } else { 77 PBECrypt.encryptFile(file, newfile, passphrase, seed.getBytes(), algorithm); 78 } 79 else 80 PBECrypt.decryptFile(file, newfile, passphrase, algorithm); 81 } catch (Exception e) { 82 Clean.blank(passphrase); 84 passphrase = null; 85 throw new JspException ("JCE Exception: " + e.getMessage(), e); 86 } 87 88 Clean.blank(passphrase); 90 passphrase = null; 91 92 return SKIP_BODY; 93 } 94 95 102 public void setPassphrase(StringBuffer passphrase) { 103 this.passphrase = passphrase; 104 } 105 106 113 public void setAlgorithm(String algorithm) { 114 this.algorithm = algorithm; 115 } 116 117 124 public void setSeed(String seed) { 125 this.seed = seed; 126 } 127 128 135 public void setAction(String action) { 136 this.action = action; 137 } 138 139 146 public void setFile(String file) { 147 this.file = file; 148 } 149 150 157 public void setNewfile(String newfile) { 158 this.newfile = newfile; 159 } 160 } | Popular Tags |