本文整理匯總了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));
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}