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


Java SecurityHelper.createSecretKey方法代码示例

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


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

示例1: ACCOUNT_AUTHORIZE_REQUEST

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void ACCOUNT_AUTHORIZE_REQUEST() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	// b5f01d3a0898d8016b5633edfe6106b0
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY,
			ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	Message message = messageService.createClient(ACCOUNT_ID,
			CoreMessageType.ACCOUNT_AUTHORIZE_REQUEST);
	message.addString(ACCOUNT_ID);
	message.addString(PASSWORD);
	accountSocklet.service(message);
}
 
开发者ID:mixaceh,项目名称:openyu-socklet,代码行数:19,代码来源:AccountSockletTest.java

示例2: ACCOUNT_AUTHORIZE_REQUEST

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void ACCOUNT_AUTHORIZE_REQUEST() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	// b5f01d3a0898d8016b5633edfe6106b0
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY,
			ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	Message message = messageService.createClient(ACCOUNT_ID,
			CoreMessageType.ACCOUNT_AUTHORIZE_REQUEST);
	message.addString(ACCOUNT_ID);
	message.addString(PASSWORD);
	//
	javaConnector.send(message);
}
 
开发者ID:mixaceh,项目名称:openyu-mix,代码行数:20,代码来源:AccountSockletTest.java

示例3: encryptMd

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
/**
 * 指定key,加密建目錄
 * 
 * @param file
 * @param assignKey
 * @param algorithm
 * @return
 */
public static String encryptMd(File file, String assignKey, String algorithm) {
	StringBuilder result = new StringBuilder();
	//
	try {
		if (file != null) {
			String[] names = StringUtils.splitPreserveAllTokens(file.getPath(), File.separator);

			// 指定key
			SecretKey secretKey = SecurityHelper.createSecretKey(assignKey, algorithm);
			// 目錄加密
			for (int i = 0; i < names.length; i++) {
				String encrypt = SecurityHelper.encryptHex(names[i], secretKey, algorithm);
				result.append(encrypt);
				//
				if (i < names.length - 1) {
					result.append(File.separator);
				}
			}

			// 建目錄
			if (isNotExist(result.toString())) {
				md(result.toString());
			}
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	}
	//
	return result.toString();
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:39,代码来源:FileHelper.java

示例4: decryptMd

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
/**
 * 指定key,解密建目錄
 * 
 * @param file
 * @param assignKey
 * @param algorithm
 * @return
 */
public static String decryptMd(File file, String assignKey, String algorithm) {
	StringBuilder result = new StringBuilder();
	if (file != null) {
		// 加個後綴,避免覆蓋原始目錄
		final String SUFFIX = "-decrypt";
		//
		String[] names = StringUtils.splitPreserveAllTokens(file.getPath(), File.separator);
		StringBuilder dir = new StringBuilder();
		// 指定key
		SecretKey secretKey = SecurityHelper.createSecretKey(assignKey, algorithm);
		// 目錄解密
		for (int i = 0; i < names.length; i++) {
			byte[] decrypt = SecurityHelper.decryptHex(names[i], secretKey, algorithm);
			dir.append(ByteHelper.toString(decrypt));
			if (i == 0) {
				dir.append(SUFFIX);
			}
			//
			if (i < names.length - 1) {
				dir.append(File.separator);
			}
		}
		result.append(dir);
		//
		// 建目錄
		if (isNotExist(dir.toString())) {
			md(dir.toString());
		}
	}
	return result.toString();
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:40,代码来源:FileHelper.java

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

示例6: decryptFile

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
/**
 * 指定key,解密檔案,含目錄檔名,內容
 * 
 * @param file
 * @param assignKey
 * @param algorithm
 * @return
 */
public static DecryptFileResult decryptFile(File file, String assignKey, String algorithm) {
	DecryptFileResult result = new DecryptFileResult();
	OutputStream out = null;
	try {
		if (isExist(file)) {
			// 指定key
			SecretKey secretKey = SecurityHelper.createSecretKey(assignKey, algorithm);

			// 目錄,decryptFromHex
			String decryptDir = decryptMd(file.getParent(), assignKey, algorithm);
			// System.out.println("dir: " + decryptDir);

			// 檔名,decryptFromHex
			String decryptFileName = ByteHelper
					.toString(SecurityHelper.decryptHex(file.getName(), secretKey, algorithm));
					// System.out.println("fileName: " + decryptFileName);

			// 內容,decryptFromBase64
			byte[] contents = IoHelper.read(file);
			byte[] decryptContent = SecurityHelper.decryptBase64(contents, secretKey, algorithm);
			// System.out.println("content: " +
			// ByteHelper.toString(decryptContent));

			// System.out.println(decryptDir+" isExist:
			// "+isExist(decryptDir));
			out = IoHelper.createOutputStream(decryptDir + File.separator + decryptFileName);
			IoHelper.write(out, decryptContent);
			//
			result.setOrigFile(file);
			result.setDestName(decryptDir + File.separator + decryptFileName);
		}
	} catch (Exception ex) {
		ex.printStackTrace();
	} finally {
		// 關閉串流
		IoHelper.close(out);
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:48,代码来源:FileHelper.java

示例7: encryptAssignKey

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 指定key
// 1000000 times: 14767 mills.
// 1000000 times: 13543 mills.
// 1000000 times: 11782 mills.
public void encryptAssignKey() {
	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[] 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);// 119, -18, -62, 95, -17, 33, 105, 56, 72,
									// -20, 88, 99, -63, 106, -84, -88, 100,
									// 72, -70, -109, -58, 107, 24, 38
	assertEquals(24, result.length);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:31,代码来源:SecurityHelperTest.java

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

示例9: mac

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 3981 mills.
// 1000000 times: 3787 mills.
// 1000000 times: 3979 mills.
public void mac() {
	// String value = "";
	String value = "中文測試abcdef";
	String algorithm = "HmacMD5";
	String assignKey = "中文key123";// HmacMD5 可中英文長度不拘
	SecretKey secretKey = SecurityHelper.createSecretKey(assignKey,
			algorithm);

	byte[] result = null;

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

	SystemHelper.println(result);
	assertEquals(16, result.length);
	//
	algorithm = "HmacSHA1";
	assignKey = "FarFarAway";
	secretKey = SecurityHelper.createSecretKey(assignKey, algorithm);
	result = SecurityHelper.mac(value, secretKey, algorithm);
	SystemHelper.println(result);
	assertEquals(20, result.length);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:33,代码来源:SecurityHelperTest.java

示例10: authorize

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void authorize() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY, ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	accountService.authorize(ACCOUNT_ID, PASSWORD);
}
 
开发者ID:mixaceh,项目名称:openyu-socklet,代码行数:13,代码来源:AccountServiceImplTest.java

示例11: checkAccount

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void checkAccount() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	// b5f01d3a0898d8016b5633edfe6106b0
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY, ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	String authKey = accountService.checkAccount(ACCOUNT_ID, PASSWORD);
	System.out.println(authKey);
}
 
开发者ID:mixaceh,项目名称:openyu-socklet,代码行数:15,代码来源:AccountServiceImplTest.java

示例12: authorize

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void authorize() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	// b5f01d3a0898d8016b5633edfe6106b0
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY, ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	accountService.authorize(ACCOUNT_ID, PASSWORD);
}
 
开发者ID:mixaceh,项目名称:openyu-mix,代码行数:14,代码来源:AccountServiceImplTest.java

示例13: checkAccount

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
public void checkAccount() {
	final String ACCOUNT_ID = "TEST_ACCOUNT_1";
	final String ASSIGN_KEY = "FarFarAway";
	final String ALGORITHM = "HmacMD5";
	// b5f01d3a0898d8016b5633edfe6106b0
	SecretKey secretKey = SecurityHelper.createSecretKey(ASSIGN_KEY, ALGORITHM);
	byte[] buff = SecurityHelper.mac("1111", secretKey, ALGORITHM);
	final String PASSWORD = EncodingHelper.encodeHex(buff);
	System.out.println(PASSWORD);
	//
	String authKey = accountService.checkAccount(ACCOUNT_ID, PASSWORD);
	System.out.println(authKey);//
}
 
开发者ID:mixaceh,项目名称:openyu-mix,代码行数:15,代码来源:AccountServiceImplTest.java

示例14: createSecretKey

import org.openyu.commons.security.SecurityHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 507 mills.
// 1000000 times: 507 mills.
// 1000000 times: 491 mills.
// verified
public void createSecretKey() {
	// String assignKey = "中文key123";
	// 24 byte
	// byte[] assignKey = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2,
	// 3, 4, 5, 6, 7, 8, 9, 0,
	// 1, 2, 3, 4 };
	// byte[] assignKey = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
	String assignKey = "abcdefgh"; // [8]
	SecretKey result = null;
	//
	int count = 1;

	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		result = SecurityHelper.createSecretKey(new byte[8], "DES");
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");

	System.out.println(result.getAlgorithm() + " :"
			+ result.getEncoded().length);
	assertNotNull(result);
	//
	result = SecurityHelper.createSecretKey(new byte[24], "DESede");
	System.out.println(result.getAlgorithm() + " :"
			+ result.getEncoded().length);
	assertNotNull(result);
	//
	result = SecurityHelper.createSecretKey(new byte[16], "AES");
	System.out.println(result.getAlgorithm() + " :"
			+ result.getEncoded().length);
	assertNotNull(result);
	//
	result = SecurityHelper.createSecretKey(new byte[10], "HmacMD5");
	System.out.println(result.getAlgorithm() + " :"
			+ result.getEncoded().length);
	assertNotNull(result);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:44,代码来源:SecurityHelperTest.java


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