本文整理汇总了Java中org.openyu.commons.security.SecurityHelper.decrypt方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityHelper.decrypt方法的具体用法?Java SecurityHelper.decrypt怎么用?Java SecurityHelper.decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openyu.commons.security.SecurityHelper
的用法示例。
在下文中一共展示了SecurityHelper.decrypt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decrypt
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 隨機key
// 1000000 times: 13034 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void decrypt() {
String value = "中文測試abcdef";
String algorithm = "DES";
SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
byte[] encrypt = SecurityHelper.encrypt(value, secretKey, algorithm);
byte[] result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
result = SecurityHelper.decrypt(encrypt, secretKey, algorithm);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
SystemHelper.println(result);
assertEquals(18, result.length);
//
String stringValue = ByteHelper.toString(result);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}
示例2: decryptAssignKey
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 指定key
// 1000000 times: 13034 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void decryptAssignKey() {
String value = "中文測試abcdef";
String algorithm = "DES";
// byte[] assignKey = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
// String assignKey="ABCDEFGH"; //[8]
String assignKey = "abcdefgh"; // [8]
SecretKey secretKey = SecurityHelper.createSecretKey(assignKey,
algorithm);
byte[] encrypt = SecurityHelper.encrypt(value, secretKey, algorithm);
byte[] result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
result = SecurityHelper.decrypt(encrypt, secretKey, algorithm);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
SystemHelper.println(result);
assertEquals(18, result.length);
//
String stringValue = ByteHelper.toString(result);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}
示例3: decryptKeyPair
import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 隨機key
// 1000000 times: 13034 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void decryptKeyPair() {
String value = "中文測試abcdef";
String algorithm = "RSA";
KeyPair keyPair = SecurityHelper.randomKeyPair(1024, algorithm);
byte[] encryptValue = SecurityHelper.encrypt(value, keyPair, algorithm);
;
byte[] result = null;
int count = 1;
long beg = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
// result = SecurityHelper.decrypt(encryptValue, keyPair,
// "RSA/ECB/PKCS1Padding");
result = SecurityHelper.decrypt(encryptValue, keyPair, algorithm);
}
long end = System.currentTimeMillis();
System.out.println(count + " times: " + (end - beg) + " mills. ");
SystemHelper.println(result);
assertEquals(18, result.length);
//
String stringValue = ByteHelper.toString(result);
System.out.println(stringValue);// 中文測試abcdef
assertEquals(value, stringValue);
}
示例4: 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);
}
示例5: 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);
}