コード例 #1
0
 public ASN1Primitive ez() {
   ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
   localASN1EncodableVector.ˊ(this.amO);
   localASN1EncodableVector.ˊ(this.amP);
   localASN1EncodableVector.ˊ(this.amQ);
   return new DERSequence(localASN1EncodableVector);
 }
コード例 #2
0
ファイル: GenMsgContent.java プロジェクト: playerdrafter/oobd
 public GenMsgContent(InfoTypeAndValue[] itv) {
   ASN1EncodableVector v = new ASN1EncodableVector();
   for (int i = 0; i < itv.length; i++) {
     v.add(itv[i]);
   }
   content = new DERSequence(v);
 }
コード例 #3
0
ファイル: CRLBag.java プロジェクト: playerdrafter/oobd
  /**
   *
   *
   * <pre>
   * CRLBag ::= SEQUENCE {
   * crlId  BAG-TYPE.&id ({CRLTypes}),
   * crlValue  [0] EXPLICIT BAG-TYPE.&Type ({CRLTypes}{@crlId})
   * }
   *
   * x509CRL BAG-TYPE ::= {OCTET STRING IDENTIFIED BY {certTypes 1}
   * -- DER-encoded X.509 CRL stored in OCTET STRING
   *
   * CRLTypes BAG-TYPE ::= {
   * x509CRL,
   * ... -- For future extensions
   * }
   * </pre>
   */
  public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(crlId);
    v.add(new DERTaggedObject(0, crlValue));

    return new DERSequence(v);
  }
コード例 #4
0
  /**
   *
   *
   * <pre>
   * TimeStampTokenEvidence ::=
   *    SEQUENCE SIZE(1..MAX) OF TimeStampAndCRL
   * </pre>
   *
   * @return
   */
  public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    for (int i = 0; i != timeStampAndCRLs.length; i++) {
      v.add(timeStampAndCRLs[i]);
    }

    return new DERSequence(v);
  }
コード例 #5
0
ファイル: OOBCertHash.java プロジェクト: playerdrafter/oobd
  /**
   *
   *
   * <pre>
   * OOBCertHash ::= SEQUENCE {
   *                      hashAlg     [0] AlgorithmIdentifier     OPTIONAL,
   *                      certId      [1] CertId                  OPTIONAL,
   *                      hashVal         BIT STRING
   *                      -- hashVal is calculated over the DER encoding of the
   *                      -- self-signed certificate with the identifier certID.
   *       }
   * </pre>
   *
   * @return a basic ASN.1 object representation.
   */
  public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    addOptional(v, 0, hashAlg);
    addOptional(v, 1, certId);

    v.add(hashVal);

    return new DERSequence(v);
  }
コード例 #6
0
  /**
   * Produce an object suitable for an ASN1OutputStream.
   *
   * <pre>
   * BasicOCSPResponse       ::= SEQUENCE {
   *      tbsResponseData      ResponseData,
   *      signatureAlgorithm   AlgorithmIdentifier,
   *      signature            BIT STRING,
   *      certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
   * </pre>
   */
  public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(tbsResponseData);
    v.add(signatureAlgorithm);
    v.add(signature);
    if (certs != null) {
      v.add(new DERTaggedObject(true, 0, certs));
    }

    return new DERSequence(v);
  }
コード例 #7
0
 public ASN1EncodableVector ˊ(
     ASN1ObjectIdentifier paramASN1ObjectIdentifier, boolean paramBoolean) {
   ASN1EncodableVector localASN1EncodableVector = new ASN1EncodableVector();
   localASN1EncodableVector.ˊ(paramASN1ObjectIdentifier);
   if (!paramBoolean) {
     localASN1EncodableVector.ˊ(new UnsignedInteger(1, fy()));
     localASN1EncodableVector.ˊ(new UnsignedInteger(2, fw()));
     localASN1EncodableVector.ˊ(new UnsignedInteger(3, fA()));
     localASN1EncodableVector.ˊ(new DERTaggedObject(false, 4, new DEROctetString(fu())));
     localASN1EncodableVector.ˊ(new UnsignedInteger(5, fx()));
   }
   localASN1EncodableVector.ˊ(new DERTaggedObject(false, 6, new DEROctetString(fz())));
   if (!paramBoolean) {
     localASN1EncodableVector.ˊ(new UnsignedInteger(7, fv()));
   }
   return localASN1EncodableVector;
 }
コード例 #8
0
ファイル: SignerInfo.java プロジェクト: playerdrafter/oobd
  /**
   * Produce an object suitable for an ASN1OutputStream.
   *
   * <pre>
   *  SignerInfo ::= SEQUENCE {
   *      version Version,
   *      SignerIdentifier sid,
   *      digestAlgorithm DigestAlgorithmIdentifier,
   *      authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
   *      digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
   *      encryptedDigest EncryptedDigest,
   *      unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
   *  }
   *
   *  EncryptedDigest ::= OCTET STRING
   *
   *  DigestAlgorithmIdentifier ::= AlgorithmIdentifier
   *
   *  DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
   * </pre>
   */
  public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(version);
    v.add(sid);
    v.add(digAlgorithm);

    if (authenticatedAttributes != null) {
      v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
    }

    v.add(digEncryptionAlgorithm);
    v.add(encryptedDigest);

    if (unauthenticatedAttributes != null) {
      v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
    }

    return new DERSequence(v);
  }
コード例 #9
0
ファイル: OOBCertHash.java プロジェクト: playerdrafter/oobd
 private void addOptional(ASN1EncodableVector v, int tagNo, ASN1Encodable obj) {
   if (obj != null) {
     v.add(new DERTaggedObject(true, tagNo, obj));
   }
 }
コード例 #10
0
  public OutputEncryptor build() throws OperatorCreationException {
    final AlgorithmIdentifier algID;

    salt = new byte[20];

    if (random == null) {
      random = new SecureRandom();
    }

    random.nextBytes(salt);

    try {
      this.cipher = helper.createCipher(algOID.getId());

      if (PEMUtilities.isPKCS5Scheme2(algOID)) {
        this.paramGen = helper.createAlgorithmParameterGenerator(algOID.getId());
      } else {
        this.secKeyFact = helper.createSecretKeyFactory(algOID.getId());
      }
    } catch (GeneralSecurityException e) {
      throw new OperatorCreationException(algOID + " not available: " + e.getMessage(), e);
    }

    if (PEMUtilities.isPKCS5Scheme2(algOID)) {
      params = paramGen.generateParameters();

      try {
        KeyDerivationFunc scheme =
            new KeyDerivationFunc(algOID, ASN1Primitive.fromByteArray(params.getEncoded()));
        KeyDerivationFunc func =
            new KeyDerivationFunc(
                PKCSObjectIdentifiers.id_PBKDF2, new PBKDF2Params(salt, iterationCount));

        ASN1EncodableVector v = new ASN1EncodableVector();

        v.add(func);
        v.add(scheme);

        algID =
            new AlgorithmIdentifier(
                PKCSObjectIdentifiers.id_PBES2, PBES2Parameters.getInstance(new DERSequence(v)));
      } catch (IOException e) {
        throw new OperatorCreationException(e.getMessage(), e);
      }

      key =
          PEMUtilities.generateSecretKeyForPKCS5Scheme2(
              algOID.getId(), password, salt, iterationCount);

      try {
        cipher.init(Cipher.ENCRYPT_MODE, key, params);
      } catch (GeneralSecurityException e) {
        throw new OperatorCreationException(e.getMessage(), e);
      }
    } else if (PEMUtilities.isPKCS12(algOID)) {
      ASN1EncodableVector v = new ASN1EncodableVector();

      v.add(new DEROctetString(salt));
      v.add(new ASN1Integer(iterationCount));

      algID = new AlgorithmIdentifier(algOID, PKCS12PBEParams.getInstance(new DERSequence(v)));

      try {
        PBEKeySpec pbeSpec = new PBEKeySpec(password);
        PBEParameterSpec defParams = new PBEParameterSpec(salt, iterationCount);

        key = secKeyFact.generateSecret(pbeSpec);

        cipher.init(Cipher.ENCRYPT_MODE, key, defParams);
      } catch (GeneralSecurityException e) {
        throw new OperatorCreationException(e.getMessage(), e);
      }
    } else {
      throw new OperatorCreationException("unknown algorithm: " + algOID, null);
    }

    return new OutputEncryptor() {
      public AlgorithmIdentifier getAlgorithmIdentifier() {
        return algID;
      }

      public OutputStream getOutputStream(OutputStream encOut) {
        return new CipherOutputStream(encOut, cipher);
      }

      public GenericKey getKey() {
        return new JceGenericKey(algID, key);
      }
    };
  }