本文整理汇总了Java中org.keyczar.KeyczarKey类的典型用法代码示例。如果您正苦于以下问题:Java KeyczarKey类的具体用法?Java KeyczarKey怎么用?Java KeyczarKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyczarKey类属于org.keyczar包,在下文中一共展示了KeyczarKey类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testEncryptKey
import org.keyczar.KeyczarKey; //导入依赖的package包/类
@Test
public void testEncryptKey() throws KeyczarException {
GenericKeyczar key = Util.createKey(DefaultKeyType.AES, KeyPurpose.DECRYPT_AND_ENCRYPT);
KeyczarKey k = key.getKey(key.getMetadata().getPrimaryVersion());
String unencryptedKey = k.toString();
String encrypted = KeyczarPBEReader.encryptKey(unencryptedKey, PASSPHRASE);
PBEKeyczarKey pbeKey = KeyczarPBEReader.parsePBEMetadata(encrypted);
assertEquals(KeyczarPBEReader.DEFAULT_ITERATION_COUNT, pbeKey.iterationCount);
assertEquals(KeyczarPBEReader.SALT_BYTES, Base64Coder.decodeWebSafe(pbeKey.salt).length);
assertEquals(KeyczarPBEReader.PBE_AES_KEY_BYTES, Base64Coder.decodeWebSafe(pbeKey.iv).length);
// decrypt the key
KeyczarPBEReader reader = new KeyczarPBEReader(null, PASSPHRASE);
String out = reader.decryptKey(encrypted);
assertEquals(unencryptedKey, out);
}
示例2: StaticKeyReader
import org.keyczar.KeyczarKey; //导入依赖的package包/类
StaticKeyReader(AesKey key) {
this.metadata = new KeyMetadata(
"Imported AES", KeyPurpose.DECRYPT_AND_ENCRYPT, DefaultKeyType.AES);
KeyVersion version = new KeyVersion(0, KeyStatus.PRIMARY, false);
this.metadata.addVersion(version);
this.keys = new ArrayList<KeyczarKey>();
this.keys.add(key);
}
示例3: read
import org.keyczar.KeyczarKey; //导入依赖的package包/类
public abstract KeyczarKey read(String paramString)
throws KeyczarException;
示例4: MemoryKeyReader
import org.keyczar.KeyczarKey; //导入依赖的package包/类
public MemoryKeyReader(KeyMetadata metadata, Map<Integer, KeyczarKey> keys) {
this.metadata = metadata;
this.keys = keys;
assert keys == null || metadata.getVersions().size() == keys.size();
}
示例5: readerFromKeyczar
import org.keyczar.KeyczarKey; //导入依赖的package包/类
/**
* Create a KeyczarReader from an existing key. Useful for creating a GenericKeyczar
* to manipulate a keyset, then "re-open" the key as the correct type to use it
* Example: Crypter crypter = new Crypter(Util.readerFromKeyczar(keyczar));
*
* @param keyczar
* @return
*/
public static KeyczarReader readerFromKeyczar(GenericKeyczar keyczar) {
HashMap<Integer, KeyczarKey> keys = new HashMap<Integer, KeyczarKey>();
for (KeyVersion v : keyczar.getVersions()) {
keys.put(v.getVersionNumber(), keyczar.getKey(v));
}
return new MemoryKeyReader(keyczar.getMetadata(), keys);
}