當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。