当前位置: 首页>>代码示例>>Java>>正文


Java KeyczarReader类代码示例

本文整理汇总了Java中org.keyczar.interfaces.KeyczarReader的典型用法代码示例。如果您正苦于以下问题:Java KeyczarReader类的具体用法?Java KeyczarReader怎么用?Java KeyczarReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


KeyczarReader类属于org.keyczar.interfaces包,在下文中一共展示了KeyczarReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFallbackReader

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
private static KeyczarReader getFallbackReader(Context paramContext)
{
  try
  {
    if (!sFallbackReaderInitialized)
    {
      File localFile = new File(paramContext.getFilesDir(), FALLBACK_KEYS_FILES_SUBDIR);
      if (localFile.exists()) {
        sFallbackReader = new KeyczarFileReader(localFile.getAbsolutePath());
      }
      sFallbackReaderInitialized = true;
    }
    KeyczarReader localKeyczarReader = sFallbackReader;
    return localKeyczarReader;
  }
  finally {}
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:18,代码来源:DfeResponseVerifierImpl.java

示例2: verify

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
public final void verify(byte[] paramArrayOfByte, String paramString)
  throws DfeResponseVerifier.DfeResponseVerifierException
{
  boolean bool = internalVerify(getProdReader(this.mContext), this.mNonce, paramArrayOfByte, paramString);
  if (!bool)
  {
    KeyczarReader localKeyczarReader = getFallbackReader(this.mContext);
    if (localKeyczarReader != null)
    {
      FinskyLog.d("Retry verification using fallback keys.", new Object[0]);
      bool = internalVerify(localKeyczarReader, this.mNonce, paramArrayOfByte, paramString);
    }
  }
  if ((!bool) || (FinskyLog.DEBUG))
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Boolean.valueOf(bool);
    FinskyLog.d("Response signature verified: %b", arrayOfObject);
  }
  if (!bool) {
    throw new DfeResponseVerifier.DfeResponseVerifierException("Response signature mismatch.");
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:24,代码来源:DfeResponseVerifierImpl.java

示例3: testCreateExportKey

import org.keyczar.interfaces.KeyczarReader; //导入依赖的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

示例4: testWriteEncrypted

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
@Test
public void testWriteEncrypted() throws KeyczarException {
  GenericKeyczar keyczar = makeKey();

  final String PASSWORD = "foopassword";
  StringBuilder builder = new StringBuilder();
  JsonWriter.writeEncrypted(keyczar, PASSWORD, builder);
  String serialized = builder.toString();

  JsonParser parser = new JsonParser();
  JsonElement element = parser.parse(serialized);
  String metadata = element.getAsJsonObject().getAsJsonPrimitive("meta").getAsString();
  element = parser.parse(metadata);
  JsonPrimitive p = element.getAsJsonObject().getAsJsonPrimitive("encrypted");
  assertTrue(p.getAsBoolean());

  KeyczarReader reader = new KeyczarJsonReader(serialized);
  KeyczarPBEReader pbeReader = new KeyczarPBEReader(reader, PASSWORD);
  Crypter c = new Crypter(pbeReader);
  assertEquals("hello", c.decrypt(c.encrypt("hello")));
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:22,代码来源:JsonWriterTest.java

示例5: testSimple

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
@Test
public void testSimple() throws KeyczarException {
	KeyczarReader reader = new KeyczarJsonReader(JSON_KEY);
	KeyMetadata metadata = KeyMetadata.read(reader.getMetadata());
	assertEquals(0, metadata.getPrimaryVersion().getVersionNumber());
	assertEquals(KeyPurpose.DECRYPT_AND_ENCRYPT, metadata.getPurpose());
	assertEquals("Imported AES", metadata.getName());
	assertEquals(1, metadata.getVersions().size());
	assertEquals(0, metadata.getVersions().get(0).getVersionNumber());
	assertFalse(metadata.getVersions().get(0).isExportable());

	Crypter crypter = new Crypter(reader);
	String plaintext = "hello world";
	String encrypted = crypter.encrypt(plaintext);
	assertTrue(!encrypted.equals(plaintext));

	String decrypted = crypter.decrypt(encrypted);
	assertEquals(plaintext, decrypted);

	// TODO: Add an old version of a key; test decrypting with it
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:22,代码来源:KeyczarJsonReaderTest.java

示例6: Keyczar

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
public Keyczar(KeyczarReader paramKeyczarReader)
  throws KeyczarException
{
  this.kmd = KeyMetadata.read(paramKeyczarReader.getMetadata());
  if (!isAcceptablePurpose(this.kmd.purpose))
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = this.kmd.purpose;
    throw new KeyczarException(Messages.getString("Keyczar.UnacceptablePurpose", arrayOfObject));
  }
  if ((this.kmd.encrypted) && (!(paramKeyczarReader instanceof EncryptedReader))) {
    throw new KeyczarException(Messages.getString("Keyczar.NeedEncryptedReader", new Object[0]));
  }
  Iterator localIterator = this.kmd.versions.iterator();
  while (localIterator.hasNext())
  {
    KeyVersion localKeyVersion = (KeyVersion)localIterator.next();
    if (localKeyVersion.status == KeyStatus.PRIMARY)
    {
      if (this.primaryVersion != null) {
        throw new KeyczarException(Messages.getString("Keyczar.SinglePrimary", new Object[0]));
      }
      this.primaryVersion = localKeyVersion;
    }
    KeyType localKeyType = this.kmd.type;
    String str = paramKeyczarReader.getKey(localKeyVersion.versionNumber);
    KeyczarKey localKeyczarKey = localKeyType.getBuilder().read(str);
    LOG.debug(Messages.getString("Keyczar.ReadVersion", new Object[] { localKeyVersion }));
    this.hashMap.put(new KeyHash(localKeyczarKey.hash(), (byte)0), localKeyczarKey);
    this.versionMap.put(localKeyVersion, localKeyczarKey);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:33,代码来源:Keyczar.java

示例7: getProdReader

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
private static KeyczarReader getProdReader(Context paramContext)
{
  try
  {
    if (sProdReader == null) {
      sProdReader = new AndroidKeyczarReader(paramContext.getResources(), PROD_KEYS_ASSETS_SUBDIR);
    }
    KeyczarReader localKeyczarReader = sProdReader;
    return localKeyczarReader;
  }
  finally {}
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:13,代码来源:DfeResponseVerifierImpl.java

示例8: createKey

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
/** Returns a GenericKeyczar containing a new generated key of type. */
public static GenericKeyczar createKey(DefaultKeyType type, KeyPurpose purpose, int size)
		throws KeyczarException {
	KeyMetadata metadata = new KeyMetadata("Key", purpose, type);
	KeyczarReader reader = new MemoryKeyReader(metadata, null);
	GenericKeyczar keyczar = new GenericKeyczar(reader);
	keyczar.addVersion(KeyStatus.PRIMARY, size);
	return keyczar;
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:10,代码来源:Util.java

示例9: generate

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
@Override
public PrivateKeyInterface generate() throws CryptoError {
  try {
    KeyczarReader encryptionKey = Util.generateKeyczarReader(
        DefaultKeyType.RSA_PRIV, KeyPurpose.DECRYPT_AND_ENCRYPT, RSA_KEY_SIZE);
    KeyczarReader signingKey = Util.generateKeyczarReader(
        DefaultKeyType.RSA_PRIV, KeyPurpose.SIGN_AND_VERIFY, RSA_KEY_SIZE);
    return new KeyczarPrivateKey(encryptionKey, signingKey);
  } catch (KeyczarException e) {
    throw new KeyInterfaces.CryptoError(e);
  }
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:KeyczarKeyFactory.java

示例10: KeyczarPrivateKey

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
public KeyczarPrivateKey(KeyczarReader encryptionReader, KeyczarReader signingReader)
    throws KeyczarException {
  super(encryptionReader, signingReader);

  crypter = new Crypter(encryptionReader);
  signer = new Signer(signingReader);
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:8,代码来源:KeyczarKeyFactory.java

示例11: exportPublicKey

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
@Override
public PublicKeyInterface exportPublicKey() throws CryptoError {
  try {
    KeyczarReader publicEncrypt = Util.exportPublicKeys(encryptionKey);
    KeyczarReader publicSigning = Util.exportPublicKeys(signingKey);
    return new KeyczarPublicKey(publicEncrypt, publicSigning);
  } catch (KeyczarException e) {
    throw new CryptoError(e);
  }
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:11,代码来源:KeyczarKeyFactory.java

示例12: testGenerateKeyczarReader

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
@Test
public void testGenerateKeyczarReader() throws KeyczarException {
  KeyczarReader reader = Util.generateKeyczarReader(DefaultKeyType.AES, KeyPurpose.DECRYPT_AND_ENCRYPT);
  Crypter crypter = new Crypter(reader);

  // test that it works
  String ciphertext = crypter.encrypt(MESSAGE);
  String decrypted = crypter.decrypt(ciphertext);
  assertEquals(MESSAGE, decrypted);
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:11,代码来源:UtilTest.java

示例13: verify

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
public static void verify(String keyPath, String message, String signaturePath) throws KeyczarException {
  // Read the key, possibly decrypting using a password
  KeyczarReader reader = Util.readJsonFromPath(keyPath);
  Verifier key = new Verifier(reader);
  String signature = Util.readFile(signaturePath);

  System.out.println("verifying signature on message length " + message.length());
  if (!key.verify(message, signature)) {
    System.err.println("Signature could not be verified!\n");
    System.exit(1);
  }
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:13,代码来源:RoundTripper.java

示例14: decrypt

import org.keyczar.interfaces.KeyczarReader; //导入依赖的package包/类
public static String decrypt(String keyPath, String encryptedPath, String expectedMessage,
    DefaultKeyType expectedType, String keyPassword) throws KeyczarException {
  // Read the key, possibly decrypting using a password
  KeyczarReader reader = Util.readJsonFromPath(keyPath);
  if (keyPassword != null) {
    reader = new KeyczarPBEReader(reader, keyPassword);
  }

  KeyMetadata metadata = KeyMetadata.read(reader.getMetadata());
  if (metadata.getType() != expectedType) {
    throw new RuntimeException("Unexpected key type: " + metadata.getType());
  }

  Crypter key = new Crypter(reader);
  String data = Util.readFile(encryptedPath);
  String output = key.decrypt(data);

  if (expectedMessage != null) {
    if (output.equals(expectedMessage)) {
      System.out.println(encryptedPath + " decrypts successfully");
    } else {
      System.err.println("Decryption does not match?\n" + output);
      System.exit(1);
    }
  }
  return output;
}
 
开发者ID:WeAreWizards,项目名称:passopolis-server,代码行数:28,代码来源:RoundTripper.java

示例15: encryptSession

import org.keyczar.interfaces.KeyczarReader; //导入依赖的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


注:本文中的org.keyczar.interfaces.KeyczarReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。