本文整理匯總了Java中org.openyu.commons.security.SecurityHelper.writeSecretKey方法的典型用法代碼示例。如果您正苦於以下問題:Java SecurityHelper.writeSecretKey方法的具體用法?Java SecurityHelper.writeSecretKey怎麽用?Java SecurityHelper.writeSecretKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openyu.commons.security.SecurityHelper
的用法示例。
在下文中一共展示了SecurityHelper.writeSecretKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeSecretKey
import org.openyu.commons.security.SecurityHelper; //導入方法依賴的package包/類
@Test
public void writeSecretKey() {
SecretKey value = SecurityHelper.randomSecretKey("DES");
int count = 1;
long beg = System.currentTimeMillis();
String result = null;
for (int i = 0; i < count; i++) {
result = SecurityHelper.writeSecretKey("secretKey", value);
}
//
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
//
System.out.println(result);
}
示例2: encryptDecryptHex
import org.openyu.commons.security.SecurityHelper; //導入方法依賴的package包/類
@Test
// 1000000 times: 13034 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void encryptDecryptHex() {
String value = "中文測試abcdef";
//
String algorithm = "DES";
SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
String keyFile = "encryptDecryptByHex";
// 將key寫入檔案,給解密用
String writeKeyFile = SecurityHelper.writeSecretKey(keyFile, secretKey);
assertNotNull(writeKeyFile);
//
String encodeByHex = null;
byte[] encrypt = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
encrypt = SecurityHelper.encrypt(value, secretKey, algorithm);
encodeByHex = EncodingHelper.encodeHex(encrypt);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
System.out.println(encodeByHex.length() + ", " + encodeByHex);// 48,
// b824f54aa6cc7c0003afea7627c5c308b5e6842fcf6481cc
//
byte[] decodeByHex = EncodingHelper.decodeHex(encodeByHex);
// 從檔案讀取key
secretKey = SecurityHelper.readSecretKey(keyFile);
assertNotNull(secretKey);
//
byte[] decrypt = SecurityHelper.decrypt(decodeByHex, secretKey, "DES");
//
String stringValue = ByteHelper.toString(decrypt);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}
示例3: encryptDecryptByBase64
import org.openyu.commons.security.SecurityHelper; //導入方法依賴的package包/類
@Test
// 1000000 times: 13034 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void encryptDecryptByBase64() {
String value = "中文測試abcdef";
//
String algorithm = "DES";
SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
String keyFile = "encryptDecryptByBase64";
// 將key寫入檔案,給解密用
String writeKeyFile = SecurityHelper.writeSecretKey(keyFile, secretKey);
assertNotNull(writeKeyFile);
//
String encodeByBase64 = null;
byte[] encrypt = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
encrypt = SecurityHelper.encrypt(value, secretKey, algorithm);
encodeByBase64 = EncodingHelper.encodeBase64String(encrypt);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
System.out.println(encodeByBase64.length() + ", " + encodeByBase64);// 32,
// z1mXJdE7WYvMsde970GNk6XyyxY9a85i
//
byte[] decodeByBase64 = EncodingHelper.decodeBase64(encodeByBase64);
// 從檔案讀取key
secretKey = SecurityHelper.readSecretKey(keyFile);
assertNotNull(secretKey);
//
byte[] decrypt = SecurityHelper.decrypt(decodeByBase64, secretKey,
"DES");
//
String stringValue = ByteHelper.toString(decrypt);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}