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