本文整理汇总了Java中org.openyu.commons.security.SecurityHelper.encryptBase64方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityHelper.encryptBase64方法的具体用法?Java SecurityHelper.encryptBase64怎么用?Java SecurityHelper.encryptBase64使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openyu.commons.security.SecurityHelper
的用法示例。
在下文中一共展示了SecurityHelper.encryptBase64方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encryptBase64
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 12067 mills.
// 1000000 times: 12263 mills.
// 1000000 times: 11782 mills.
public void encryptBase64() {
String value = "中文測試abcdef";
String algorithm = "DES";
// 隨機key
SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
String result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
result = SecurityHelper.encryptBase64(value, secretKey, algorithm);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
System.out.println(result);// At4nhIRyIZTbCVXpO+kz7NigWmiuz9Up
assertEquals(32, result.length());
}
示例2: encryptFile
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
/**
* 指定key,加密檔案,含目錄檔名,內容
*
* @param file
* @param assignKey
* @param algorithm
* @return
*/
public static EncryptFileResult encryptFile(File file, String assignKey, String algorithm) {
EncryptFileResult result = new EncryptFileResult();
if (isExist(file)) {
// 指定key
SecretKey secretKey = SecurityHelper.createSecretKey(assignKey, algorithm);
// 目錄,encryptToHex
String encryptDir = encryptMd(file.getParent(), assignKey, algorithm);
// System.out.println("dir: " + encryptDir);
// 檔名,encryptToHex
String encryptFileName = SecurityHelper.encryptHex(file.getName(), secretKey, algorithm);
// System.out.println("fileName: " + encryptFileName);
// 內容,encryptToBase64
byte[] contents = IoHelper.read(file);
String encryptContent = SecurityHelper.encryptBase64(contents, secretKey, algorithm);
// System.out.println("content: " + encryptContent);
//
Writer writer = IoHelper.createWriter(encryptDir + File.separator + encryptFileName);
try {
IoHelper.write(writer, encryptContent);
//
result.setOrigFile(file);
result.setDestName(encryptDir + File.separator + encryptFileName);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
// 關閉串流
IoHelper.close(writer);
}
}
return result;
}
示例3: decryptBase64
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 7901 mills.
// 1000000 times: 7812 mills.
// 1000000 times: 8108 mills.
public void decryptBase64() {
String value = "中文測試abcdef";
String algorithm = "DES";
// 隨機key
SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
String encryptToBase64 = SecurityHelper.encryptBase64(value, secretKey,
algorithm);
byte[] result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
result = SecurityHelper.decryptBase64(encryptToBase64, secretKey,
algorithm);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
SystemHelper.println(result);// -28, -72, -83, -26, -106, -121, -26,
// -72, -84, -24, -87, -90, 97, 98, 99,
// 100, 101, 102
assertEquals(18, result.length);
//
String stringValue = ByteHelper.toString(result);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}