本文整理汇总了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);
}