Package org.keyczar.exceptions

Examples of org.keyczar.exceptions.KeyczarException


      throws KeyczarException {
    try {
      return Base64Coder.encode(timeoutSign(input.getBytes(
          Keyczar.DEFAULT_ENCODING), expirationTime));
    } catch (UnsupportedEncodingException e) {
      throw new KeyczarException(e);
    }
  
  }
View Full Code Here


    return encrypter.encrypt(sessionMaterial.toString());
  }

  private AesKey buildSessionKey(AesKeyParameters params) throws KeyczarException {
    if (!DefaultKeyType.AES.isAcceptableSize(params.getKeySize())) {
      throw new KeyczarException("Unsupported key size requested for session");
    }
    return AesKey.generate(params);
  }
View Full Code Here

   * @return encrypted payload with signing attached.
   * @throws KeyczarException
   */
  public byte[] encrypt(byte[] plainText) throws KeyczarException {
  if (null == session.get()) {
      throw new KeyczarException("Session not initialized.");
  }

    SessionMaterial material = session.get();
    ImportedKeyReader importedKeyReader = new ImportedKeyReader(material.getKey());
    Crypter symmetricCrypter = new Crypter(importedKeyReader);
View Full Code Here

          return RsaPrivateKey.generate((RsaKeyParameters) params);
        // Currently unsupported. See "unofficial" directory.
        //case EC_PRIV:
        //    return EcPrivateKey.generate(keySize);
        case RSA_PUB: case DSA_PUB:
          throw new KeyczarException(Messages.getString(
              "KeyczarKey.PublicKeyExport", DefaultKeyType.this));
      }
      throw new UnsupportedTypeException(DefaultKeyType.this);
    }
View Full Code Here

   * @throws KeyczarException
   */
  public X509CertificateReader(KeyPurpose purpose, InputStream certificateStream, RsaPadding padding)
      throws KeyczarException {
    if (purpose == null) {
      throw new KeyczarException("X509Certificate purpose must not be null");
  }
  if (certificateStream == null) {
    throw new KeyczarException("X509Certificate stream must not be null");
  }
    this.purpose = purpose;
    this.certificateStream = certificateStream;
    this.padding = padding;
  }
View Full Code Here

    if (key == null) {
      try {
        parseCertificate();
        constructMetadata();
      } catch (CertificateException e) {
        throw new KeyczarException(Messages.getString("KeyczarTool.InvalidCertificate"), e);
      }
    }
  }
View Full Code Here

    }
  }

  private void constructMetadata() throws KeyczarException {
    if (purpose == KeyPurpose.ENCRYPT && key.getType() == DefaultKeyType.DSA_PUB) {
      throw new KeyczarException(Messages.getString("Keyczartool.InvalidUseOfDsaKey"));
    }
    meta = new KeyMetadata("imported from certificate", purpose, key.getType());
    meta.addVersion(new KeyVersion(1, KeyStatus.PRIMARY, true /* exportable */));
  }
View Full Code Here

    if (publicKey instanceof RSAPublicKey) {
      key = new RsaPublicKey((RSAPublicKey) publicKey, padding);
    } else if (publicKey instanceof DSAPublicKey) {
      if (padding != null) {
        throw new KeyczarException(Messages.getString("InvalidPadding", padding.name()));
      }
      key = new DsaPublicKey((DSAPublicKey) publicKey);
    } else {
      throw new KeyczarException("Unrecognized key type " + publicKey.getAlgorithm() +
          " in certificate");
    }
  }
View Full Code Here

   * @return PEM-format key data.
   */
  public String getPemString(String passphrase) throws KeyczarException {
    if (isSecret()) {
      if (passphrase == null || passphrase.length() < 8) {
        throw new KeyczarException(Messages.getString("KeyczarTool.PassphraseRequired"));
      }
      return convertDerToPem(encryptPrivateKey(getJceKey(), passphrase));
    } else {
      if (passphrase != null && !"".equals(passphrase)) {
        throw new KeyczarException(Messages.getString("KeyczarTool.PassphraseNotAllowed"));
      }
      return convertDerToPem(getJceKey().getEncoded());
    }
  }
View Full Code Here

          Cipher.ENCRYPT_MODE, pkcs8EncryptionKey, new PBEParameterSpec(salt, PBE_ITERATION_COUNT));
      byte[] encryptedKey = cipher.doFinal(key.getEncoded());
      EncryptedPrivateKeyInfo inf = new EncryptedPrivateKeyInfo(cipher.getParameters(), encryptedKey);
      return inf.getEncoded();
    } catch (GeneralSecurityException e) {
      throw new KeyczarException(Messages.getString("KeyczarTool.FailedToEncryptPrivateKey"), e);
    } catch (IOException e) {
      // This should be impossible.
      throw new KeyczarException(Messages.getString("KeyczarTool.FailedToEncryptPrivateKey"), e);
    }
  }
View Full Code Here

TOP

Related Classes of org.keyczar.exceptions.KeyczarException

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.