当前位置: 首页>>代码示例>>Java>>正文


Java SecurityHelper.randomSecretKey方法代码示例

本文整理汇总了Java中org.openyu.commons.security.SecurityHelper.randomSecretKey方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityHelper.randomSecretKey方法的具体用法?Java SecurityHelper.randomSecretKey怎么用?Java SecurityHelper.randomSecretKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openyu.commons.security.SecurityHelper的用法示例。


在下文中一共展示了SecurityHelper.randomSecretKey方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encrypt

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 14767 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void encrypt() {
	String value = "中文測試abcdef";

	String algorithm = "DES";
	// 隨機key
	SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
	byte[] result = null;

	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		result = SecurityHelper.encrypt(value, secretKey, algorithm);
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");

	SystemHelper.println(result);
	assertEquals(24, result.length);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:24,代码来源:SecurityHelperTest.java

示例2: encryptHex

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 7901 mills.
// 1000000 times: 7812 mills.
// 1000000 times: 8108 mills.
public void encryptHex() {
	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.encryptHex(value, secretKey, algorithm);
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");

	System.out.println(result);// 986985ea51dca188906abf8b2a1b8a4eed800729efb7b580
	assertEquals(48, result.length());
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:24,代码来源:SecurityHelperTest.java

示例3: 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());
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:24,代码来源:SecurityHelperTest.java

示例4: 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:17,代码来源:SecurityHelperTest.java

示例5: randomSecretKey

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 6007 mills.
// 1000000 times: 5790 mills.
// 1000000 times: 6157 mills.
// verified
public void randomSecretKey() {
	SecretKey result = null;
	//
	int count = 1000;

	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		result = SecurityHelper.randomSecretKey("DES");
		System.out.println("[" + i + "] "
				+ ByteHelper.toString(result.getEncoded()));
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");

	System.out.println(result.getAlgorithm() + " :"
			+ ByteHelper.toString(result.getEncoded()));
	assertNotNull(result);
	//
	result = SecurityHelper.randomSecretKey("DESede");
	System.out.println(result.getAlgorithm() + " :"
			+ ByteHelper.toString(result.getEncoded()));
	assertNotNull(result);
	//
	result = SecurityHelper.randomSecretKey("HmacMD5");
	System.out.println(result.getAlgorithm() + " :"
			+ ByteHelper.toString(result.getEncoded()));
	assertNotNull(result);
	//
	result = SecurityHelper.randomSecretKey("AES");
	System.out.println(result.getAlgorithm() + " :"
			+ ByteHelper.toString(result.getEncoded()));
	assertNotNull(result);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:39,代码来源:SecurityHelperTest.java

示例6: decryptHex

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 7901 mills.
// 1000000 times: 7812 mills.
// 1000000 times: 8108 mills.
public void decryptHex() {
	String value = "中文測試abcdef";

	String algorithm = "DES";
	String assignKey = "abcdefgh01234567abcdefgh";
	// 隨機key
	SecretKey secretKey = SecurityHelper.randomSecretKey(algorithm);
	String encryptToHex = SecurityHelper.encryptHex(value, secretKey,
			algorithm);
	byte[] result = null;

	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		result = SecurityHelper.decryptHex(encryptToHex, 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:34,代码来源:SecurityHelperTest.java

示例7: 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:33,代码来源:SecurityHelperTest.java

示例8: 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:30,代码来源:SecurityHelperTest.java

示例9: 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:42,代码来源:SecurityHelperTest.java

示例10: 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);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:43,代码来源:SecurityHelperTest.java


注:本文中的org.openyu.commons.security.SecurityHelper.randomSecretKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。