Package org.keyczar

Examples of org.keyczar.Crypter


        // TODO: Cache??
        return KeyczarUtils.buildCrypter(cryptoKey);
    }

    byte[] decrypt(byte[] ciphertext) throws KeyczarException {
        Crypter crypter = getCrypter();
        return crypter.decrypt(ciphertext);
    }
View Full Code Here


        try {
            if (privateKey == null) {
                privateKey = KeyczarUtils.readRsaPrivateKey(userSecretData.getPrivateKey().getKeyczar());
            }
            // TODO: Cache crypter?
            return new Crypter(new KeyczarReaderWrapper(privateKey));
        } catch (KeyczarException e) {
            throw new IllegalStateException("Error reading private key", e);
        }
    }
View Full Code Here

  @Override
  public byte[] generate(String algorithm, Map<String, String> generateParams)
      throws KeyczarException {
    if (generateParams.get("class").equals("crypter")) {
      Crypter crypter = new Crypter(
          getReader(algorithm, generateParams.get("cryptedKeySet"), generateParams.get("pubKey")));
      if (generateParams.get("encoding").equals("encoded")) {
        String ciphertext = crypter.encrypt(testData);
        return ciphertext.getBytes();
      } else if (generateParams.get("encoding").equals("unencoded")) {
        byte[] ciphertext = crypter.encrypt(testData.getBytes());
        return ciphertext;
      } else {
        throw new KeyczarException("Expects encoded or unencoded in parameters");
      }
    } else if (generateParams.get("class").equals("encrypter")) {
      Encrypter crypter = new Encrypter(
          getReader(algorithm, generateParams.get("cryptedKeySet"), generateParams.get("pubKey")));
      if (generateParams.get("encoding").equals("encoded")) {
        String ciphertext = crypter.encrypt(testData);
        return ciphertext.getBytes();
      } else if (generateParams.get("encoding").equals("unencoded")) {
        byte[] ciphertext = crypter.encrypt(testData.getBytes());
        return ciphertext;
      } else {
        throw new KeyczarException("Expects encoded or unencoded in parameters");
      }
    } else {
View Full Code Here

  @Override
  public void test(
      Map<String, String> output, String algorithm, Map<String, String> generateParams,
      Map<String, String> testParams) throws KeyczarException {
    Crypter crypter = new Crypter(
        getReader(algorithm, generateParams.get("cryptedKeySet"), ""));
    if (generateParams.get("encoding").equals("encoded")) {
      String plaintext = crypter.decrypt(new String(readOutput(output)));
      assert(plaintext.equals(testData));
    } else if (generateParams.get("encoding").equals("unencoded")) {
      byte[] plaintext = crypter.decrypt(readOutput(output));
      assert((new String(plaintext)).equals(testData));
    } else {
      throw new KeyczarException("Expects encoded or unencoded in parameters");
    }
  }
View Full Code Here

    if (pubKey != null) {
      keysetName += pubKey;
    }
    KeyczarReader reader = new KeyczarFileReader(getKeyPath(keysetName));
    if (!crypterAlgorithm.equals("")) {
      Crypter crypter = new Crypter(getKeyPath(crypterAlgorithm));
      reader = new KeyczarEncryptedReader(reader, crypter);
    }
    return reader;
  }
View Full Code Here

      Map<String, String> testParams) throws KeyczarException {
    Gson gson = new Gson();
    byte[] encryptedData = readOutput(output);
    String sessionMaterial = output.get("sessionMaterial");
   
    Crypter keyCrypter = new Crypter(
        getReader(algorithm, generateParams.get("cryptedKeySet"), testParams.get("pubKey")));
    Verifier verifier = new Verifier(getReader(
        generateParams.get("signer"), generateParams.get("cryptedKeySet"), ""));
    SignedSessionDecrypter sessionCrypter =
        new SignedSessionDecrypter(keyCrypter, verifier, sessionMaterial);
View Full Code Here

  public SessionDecrypter(Crypter crypter, byte[] sessionMaterial)
      throws KeyczarException {
    byte[] packedKeys = crypter.decrypt(sessionMaterial);
    AesKey aesKey = AesKey.fromPackedKey(packedKeys);
    ImportedKeyReader importedKeyReader = new ImportedKeyReader(aesKey);
    this.symmetricCrypter = new Crypter(importedKeyReader);
  }
View Full Code Here

   */
  public SessionEncrypter(Encrypter encrypter) throws KeyczarException {
    // Using minimum acceptable AES key size, which is 128 bits
    AesKey aesKey = AesKey.generate(KeyType.AES.getAcceptableSizes().get(0));
    ImportedKeyReader importedKeyReader = new ImportedKeyReader(aesKey);
    this.symmetricCrypter = new Crypter(importedKeyReader);
    this.sessionMaterial = encrypter.encrypt(aesKey.getEncoded());
  }
View Full Code Here

TOP

Related Classes of org.keyczar.Crypter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.