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


Java Encrypter类代码示例

本文整理汇总了Java中org.keyczar.Encrypter的典型用法代码示例。如果您正苦于以下问题:Java Encrypter类的具体用法?Java Encrypter怎么用?Java Encrypter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testCreateExportKey

import org.keyczar.Encrypter; //导入依赖的package包/类
@Test
public void testCreateExportKey() throws KeyczarException {
	// create the key, export the public key; 1024 bits is the smallest size
	GenericKeyczar keyczar = Util.createKey(
	    DefaultKeyType.RSA_PRIV, KeyPurpose.DECRYPT_AND_ENCRYPT, 1024);
	KeyczarReader publicKeyReader = Util.exportPublicKeys(keyczar);
	Encrypter encrypter = new Encrypter(publicKeyReader);

	// test that it works
	String ciphertext = encrypter.encrypt(MESSAGE);
	Crypter crypter = new Crypter(Util.readerFromKeyczar(keyczar));
	String decrypted = crypter.decrypt(ciphertext);
	assertEquals(MESSAGE, decrypted);

	// test a session
	StringBuilder longMessage = new StringBuilder("hello message ");
	while (longMessage.length() < 500) {
		longMessage.append(longMessage);
	}

	ciphertext = Util.encryptWithSession(encrypter, longMessage.toString());
	assertEquals(longMessage.toString(), Util.decryptWithSession(crypter, ciphertext));
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:24,代码来源:UtilTest.java

示例2: encryptWithSession

import org.keyczar.Encrypter; //导入依赖的package包/类
/**
 * Encrypts plaintext with a new session key, which is encrypted using crypter. The encrypted session
 * key and encrypted message are packed together using lenPrefixPack().
 */
public static byte[] encryptWithSession(Encrypter crypter, byte[] plaintext) throws KeyczarException {
	// Create a session crypter
	SessionCrypter session = new SessionCrypter(crypter);
	byte[] rawEncrypted = session.encrypt(plaintext);
	byte[][] input = {session.getSessionMaterial(), rawEncrypted};
	return org.keyczar.util.Util.lenPrefixPack(input);
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:12,代码来源:Util.java

示例3: encrypt

import org.keyczar.Encrypter; //导入依赖的package包/类
private static void encrypt(String keyPath, String message, String outpath) throws KeyczarException, IOException {
  Encrypter key = new Encrypter(Util.readJsonFromPath(keyPath));
  System.out.println("encrypting message length " + message.length());
  String output = key.encrypt(message);

  Files.write(output, new File(outpath), Charsets.UTF_8);
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:8,代码来源:RoundTripper.java

示例4: encryptSession

import org.keyczar.Encrypter; //导入依赖的package包/类
private static void encryptSession(String keyPath, String outPath, String message) throws KeyczarException {
  KeyczarReader reader = Util.readJsonFromPath(keyPath);
  String output = Util.encryptWithSession(new Encrypter(reader), message);
  try {
    FileOutputStream out = new FileOutputStream(outPath);
    byte[] data = output.getBytes("UTF-8");
    out.write(data);
    out.close();
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:RoundTripper.java

示例5: KeyczarPublicKey

import org.keyczar.Encrypter; //导入依赖的package包/类
public KeyczarPublicKey(KeyczarReader encryptionReader, KeyczarReader signingReader)
    throws KeyczarException {
  super(encryptionReader, signingReader);
  encrypter = new Encrypter(encryptionReader);
  verifier = new Verifier(signingReader);
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:7,代码来源:KeyczarKeyFactory.java


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