Java 类org.bouncycastle.asn1.x509.AlgorithmIdentifier 实例源码

项目:ipack    文件:CertPathValidatorUtilities.java   
protected static AlgorithmIdentifier getAlgorithmIdentifier(
    PublicKey key)
    throws CertPathValidatorException
{
    try
    {
        ASN1InputStream aIn = new ASN1InputStream(key.getEncoded());

        SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(aIn.readObject());

        return info.getAlgorithmId();
    }
    catch (Exception e)
    {
        throw new ExtCertPathValidatorException("Subject public key cannot be decoded.", e);
    }
}
项目:ipack    文件:SignedPublicKeyAndChallenge.java   
public PublicKey getPublicKey(String provider)
    throws NoSuchAlgorithmException, NoSuchProviderException, 
           InvalidKeyException
{
    SubjectPublicKeyInfo subjectPKInfo = pkac.getSubjectPublicKeyInfo();
    try
    {
        DERBitString bStr = new DERBitString(subjectPKInfo);
        X509EncodedKeySpec xspec = new X509EncodedKeySpec(bStr.getBytes());


        AlgorithmIdentifier keyAlg = subjectPKInfo.getAlgorithm();

        KeyFactory factory =
            KeyFactory.getInstance(keyAlg.getAlgorithm().getId(),provider);

        return factory.generatePublic(xspec);

    }
    catch (Exception e)
    {
        throw new InvalidKeyException("error encoding public key");
    }
}
项目:ipack    文件:PKCS10CertificationRequest.java   
static String getSignatureName(
    AlgorithmIdentifier sigAlgId)
{
    ASN1Encodable params = sigAlgId.getParameters();

    if (params != null && !DERNull.INSTANCE.equals(params))
    {
        if (sigAlgId.getObjectId().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
        {
            RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);
            return getDigestAlgName(rsaParams.getHashAlgorithm().getObjectId()) + "withRSAandMGF1";
        }
    }

    return sigAlgId.getObjectId().getId();
}
项目:ipack    文件:BCMcEliecePublicKey.java   
/**
 * Return the keyData to encode in the SubjectPublicKeyInfo structure.
 * <p/>
 * The ASN.1 definition of the key structure is
 * <p/>
 * <pre>
 *       McEliecePublicKey ::= SEQUENCE {
 *         n           Integer      -- length of the code
 *         t           Integer      -- error correcting capability
 *         matrixG     OctetString  -- generator matrix as octet string
 *       }
 * </pre>
 *
 * @return the keyData to encode in the SubjectPublicKeyInfo structure
 */
public byte[] getEncoded()
{
    McEliecePublicKey key = new McEliecePublicKey(new ASN1ObjectIdentifier(oid), n, t, g);
    AlgorithmIdentifier algorithmIdentifier = new AlgorithmIdentifier(this.getOID(), DERNull.INSTANCE);

    try
    {
        SubjectPublicKeyInfo subjectPublicKeyInfo = new SubjectPublicKeyInfo(algorithmIdentifier, key);

        return subjectPublicKeyInfo.getEncoded();
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:xitk    文件:AlgorithmUtil.java   
public static AlgorithmCode getSigOrMacAlgoCode(AlgorithmIdentifier algId)
        throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier oid = algId.getAlgorithm();
    AlgorithmCode code = algOidToCodeMap.get(oid);
    if (code != null) {
        return code;
    }

    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(oid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(algId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        code = digestToMgf1AlgCodeMap.get(digestAlgOid);
        if (code == null) {
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid);
        }
        return code;
    } else {
        throw new NoSuchAlgorithmException("unsupported signature algorithm "
                + oid.getId());
    }
}
项目:ipack    文件:JceAsymmetricValueDecryptorGenerator.java   
public InputDecryptor getValueDecryptor(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CRMFException
{
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);

    final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);

    return new InputDecryptor()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataIn)
        {
            return new CipherInputStream(dataIn, dataCipher);
        }
    };
}
项目:xitk    文件:P11DSAContentSigner.java   
P11DSAContentSigner(P11CryptService cryptService, P11EntityIdentifier identityId,
        AlgorithmIdentifier signatureAlgId, boolean plain)
        throws XiSecurityException, P11TokenException {
    this.identityId = ParamUtil.requireNonNull("identityId", identityId);
    this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService);
    this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId);
    try {
        this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded();
    } catch (IOException ex) {
        throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
    }
    this.plain = plain;

    String algOid = signatureAlgId.getAlgorithm().getId();
    HashAlgoType hashAlgo = sigAlgHashMap.get(algOid);
    if (hashAlgo == null) {
        throw new XiSecurityException("unsupported signature algorithm " + algOid);
    }

    P11SlotIdentifier slotId = identityId.slotId();
    P11Slot slot = cryptService.getSlot(slotId);
    if (slot.supportsMechanism(PKCS11Constants.CKM_DSA)) {
        this.mechanism = PKCS11Constants.CKM_DSA;
        Digest digest = hashAlgo.createDigest();
        this.outputStream = new DigestOutputStream(digest);
    } else {
        this.mechanism = hashMechMap.get(hashAlgo).longValue();
        if (!slot.supportsMechanism(this.mechanism)) {
            throw new XiSecurityException("unsupported signature algorithm " + algOid);
        }

        this.outputStream = new ByteArrayOutputStream();
    }
}
项目:ipack    文件:EnvelopedDataHelper.java   
AlgorithmIdentifier getAlgorithmIdentifier(ASN1ObjectIdentifier encryptionOID, AlgorithmParameters params)
    throws CMSException
{
    ASN1Encodable asn1Params;
    if (params != null)
    {
        try
        {
            asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1"));
        }
        catch (IOException e)
        {
            throw new CMSException("cannot encode parameters: " + e.getMessage(), e);
        }
    }
    else
    {
        asn1Params = DERNull.INSTANCE;
    }

    return new AlgorithmIdentifier(
        encryptionOID,
        asn1Params);
}
项目:ipack    文件:CMSEnvelopedGenerator.java   
protected AlgorithmIdentifier getAlgorithmIdentifier(String encryptionOID, AlgorithmParameters params) throws IOException
{
    ASN1Encodable asn1Params;
    if (params != null)
    {
        asn1Params = ASN1Primitive.fromByteArray(params.getEncoded("ASN.1"));
    }
    else
    {
        asn1Params = DERNull.INSTANCE;
    }

    return new AlgorithmIdentifier(
        new ASN1ObjectIdentifier(encryptionOID),
        asn1Params);
}
项目:xitk    文件:HmacContentSigner.java   
public HmacContentSigner(HashAlgoType hashAlgo, AlgorithmIdentifier algorithmIdentifier,
        SecretKey signingKey) throws XiSecurityException {
    this.algorithmIdentifier = ParamUtil.requireNonNull("algorithmIdentifier",
            algorithmIdentifier);
    try {
        this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded();
    } catch (IOException ex) {
        throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
    }
    ParamUtil.requireNonNull("signingKey", signingKey);
    if (hashAlgo == null) {
        hashAlgo = AlgorithmUtil.extractHashAlgoFromMacAlg(algorithmIdentifier);
    }

    this.hmac = new HMac(hashAlgo.createDigest());
    byte[] keyBytes = signingKey.getEncoded();
    this.hmac.init(new KeyParameter(keyBytes, 0, keyBytes.length));
    this.outLen = hmac.getMacSize();
    this.outputStream = new HmacOutputStream();
}
项目:ipack    文件:AESUtil.java   
static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
{
    int length = key.getKey().length * 8;
    ASN1ObjectIdentifier wrapOid;

    if (length == 128)
    {
        wrapOid = NISTObjectIdentifiers.id_aes128_wrap;
    }
    else if (length == 192)
    {
        wrapOid = NISTObjectIdentifiers.id_aes192_wrap;
    }
    else if (length == 256)
    {
        wrapOid = NISTObjectIdentifiers.id_aes256_wrap;
    }
    else
    {
        throw new IllegalArgumentException("illegal keysize in AES");
    }

    return new AlgorithmIdentifier(wrapOid); // parameters absent
}
项目:ipack    文件:KeyAgreeRecipientInfo.java   
public KeyAgreeRecipientInfo(
    ASN1Sequence seq)
{
    int index = 0;

    version = (ASN1Integer)seq.getObjectAt(index++);
    originator = OriginatorIdentifierOrKey.getInstance(
                        (ASN1TaggedObject)seq.getObjectAt(index++), true);

    if (seq.getObjectAt(index) instanceof ASN1TaggedObject)
    {
        ukm = ASN1OctetString.getInstance(
                        (ASN1TaggedObject)seq.getObjectAt(index++), true);
    }

    keyEncryptionAlgorithm = AlgorithmIdentifier.getInstance(
                                            seq.getObjectAt(index++));

    recipientEncryptedKeys = (ASN1Sequence)seq.getObjectAt(index++);
}
项目:xitk    文件:AlgorithmUtil.java   
public static String getSignatureAlgoName(AlgorithmIdentifier sigAlgId)
        throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);

    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
    String name = null;
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        name = digestOidToMgf1SigNameMap.get(digestAlgOid);
        if (name == null) {
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid);
        }
    } else {
        name = sigAlgOidToNameMap.get(algOid);
    }

    if (name == null) {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId());
    }
    return name;
}
项目:ipack    文件:SignerInfo.java   
public SignerInfo(
    SignerIdentifier        sid,
    AlgorithmIdentifier     digAlgorithm,
    Attributes              authenticatedAttributes,
    AlgorithmIdentifier     digEncryptionAlgorithm,
    ASN1OctetString         encryptedDigest,
    Attributes              unauthenticatedAttributes)
{
    if (sid.isTagged())
    {
        this.version = new ASN1Integer(3);
    }
    else
    {
        this.version = new ASN1Integer(1);
    }

    this.sid = sid;
    this.digAlgorithm = digAlgorithm;
    this.authenticatedAttributes = ASN1Set.getInstance(authenticatedAttributes);
    this.digEncryptionAlgorithm = digEncryptionAlgorithm;
    this.encryptedDigest = encryptedDigest;
    this.unauthenticatedAttributes = ASN1Set.getInstance(unauthenticatedAttributes);
}
项目:ipack    文件:SignerInfo.java   
public SignerInfo(
    ASN1Integer              version,
    IssuerAndSerialNumber   issuerAndSerialNumber,
    AlgorithmIdentifier     digAlgorithm,
    ASN1Set                 authenticatedAttributes,
    AlgorithmIdentifier     digEncryptionAlgorithm,
    ASN1OctetString         encryptedDigest,
    ASN1Set                 unauthenticatedAttributes)
{
    this.version = version;
    this.issuerAndSerialNumber = issuerAndSerialNumber;
    this.digAlgorithm = digAlgorithm;
    this.authenticatedAttributes = authenticatedAttributes;
    this.digEncryptionAlgorithm = digEncryptionAlgorithm;
    this.encryptedDigest = encryptedDigest;
    this.unauthenticatedAttributes = unauthenticatedAttributes;
}
项目:ipack    文件:X509SignatureUtil.java   
static String getSignatureName(
    AlgorithmIdentifier sigAlgId) 
{
    ASN1Encodable params = sigAlgId.getParameters();

    if (params != null && !derNull.equals(params))
    {
        if (sigAlgId.getObjectId().equals(PKCSObjectIdentifiers.id_RSASSA_PSS))
        {
            RSASSAPSSparams rsaParams = RSASSAPSSparams.getInstance(params);

            return getDigestAlgName(rsaParams.getHashAlgorithm().getObjectId()) + "withRSAandMGF1";
        }
        if (sigAlgId.getObjectId().equals(X9ObjectIdentifiers.ecdsa_with_SHA2))
        {
            ASN1Sequence ecDsaParams = ASN1Sequence.getInstance(params);

            return getDigestAlgName((DERObjectIdentifier)ecDsaParams.getObjectAt(0)) + "withECDSA";
        }
    }

    return sigAlgId.getObjectId().getId();
}
项目:xitk    文件:DfltConcurrentContentSigner.java   
public DfltConcurrentContentSigner(boolean mac, List<XiContentSigner> signers,
        Key signingKey) throws NoSuchAlgorithmException {
    ParamUtil.requireNonEmpty("signers", signers);

    this.mac = mac;
    AlgorithmIdentifier algorithmIdentifier = signers.get(0).getAlgorithmIdentifier();
    this.algorithmName = AlgorithmUtil.getSigOrMacAlgoName(algorithmIdentifier);
    this.algorithmCode = AlgorithmUtil.getSigOrMacAlgoCode(algorithmIdentifier);

    for (XiContentSigner signer : signers) {
        this.signers.add(new ConcurrentBagEntrySigner(signer));
    }

    this.signingKey = signingKey;
    this.name = "defaultSigner-" + NAME_INDEX.getAndIncrement();
}
项目:ipack    文件:PKCS12PfxPdu.java   
/**
 * Verify the MacData attached to the PFX is consistent with what is expected.
 *
 * @param macCalcProviderBuilder provider builder for the calculator for the MAC
 * @param password password to use
 * @return true if mac data is valid, false otherwise.
 * @throws PKCSException if there is a problem evaluating the MAC.
 * @throws IllegalStateException if no MAC is actually present
 */
public boolean isMacValid(PKCS12MacCalculatorBuilderProvider macCalcProviderBuilder, char[] password)
    throws PKCSException
{
    if (hasMac())
    {
        MacData pfxmData = pfx.getMacData();
        MacDataGenerator mdGen = new MacDataGenerator(macCalcProviderBuilder.get(new AlgorithmIdentifier(pfxmData.getMac().getAlgorithmId().getAlgorithm(), new PKCS12PBEParams(pfxmData.getSalt(), pfxmData.getIterationCount().intValue()))));

        try
        {
            MacData mData = mdGen.build(
                password,
                ASN1OctetString.getInstance(pfx.getAuthSafe().getContent()).getOctets());

            return Arrays.constantTimeAreEqual(mData.getEncoded(), pfx.getMacData().getEncoded());
        }
        catch (IOException e)
        {
            throw new PKCSException("unable to process AuthSafe: " + e.getMessage());
        }
    }

    throw new IllegalStateException("no MAC present on PFX");
}
项目:ipack    文件:CertID.java   
private CertID(
    ASN1Sequence    seq)
{
    hashAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(0));
    issuerNameHash = (ASN1OctetString)seq.getObjectAt(1);
    issuerKeyHash = (ASN1OctetString)seq.getObjectAt(2);
    serialNumber = (ASN1Integer)seq.getObjectAt(3);
}
项目:ipack    文件:X509Util.java   
private static RSASSAPSSparams creatPSSParams(AlgorithmIdentifier hashAlgId, int saltSize)
{
    return new RSASSAPSSparams(
        hashAlgId,
        new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, hashAlgId),
        new ASN1Integer(saltSize),
        new ASN1Integer(1));
}
项目:ipack    文件:KeyUtil.java   
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, byte[] keyData)
{
    try
    {
        return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
    }
    catch (Exception e)
    {
        return null;
    }
}
项目:ipack    文件:CertUtils.java   
private static Certificate generateStructure(TBSCertificate tbsCert, AlgorithmIdentifier sigAlgId, byte[] signature)
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(tbsCert);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));

    return Certificate.getInstance(new DERSequence(v));
}
项目:ipack    文件:CertUtils.java   
private static CertificateList generateCRLStructure(TBSCertList tbsCertList, AlgorithmIdentifier sigAlgId, byte[] signature)
{
    ASN1EncodableVector v = new ASN1EncodableVector();

    v.add(tbsCertList);
    v.add(sigAlgId);
    v.add(new DERBitString(signature));

    return CertificateList.getInstance(new DERSequence(v));
}
项目:ipack    文件:BCElGamalPrivateKey.java   
/**
 * Return a PKCS8 representation of the key. The sequence returned
 * represents a full PrivateKeyInfo object.
 *
 * @return a PKCS8 representation of the key.
 */
public byte[] getEncoded()
{
    try
    {
        PrivateKeyInfo          info = new PrivateKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(elSpec.getP(), elSpec.getG())), new DERInteger(getX()));

        return info.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        return null;
    }
}
项目:ipack    文件:CertificateID.java   
/**
 * create from an issuer certificate and the serial number of the
 * certificate it signed.
 *
 * @param hashAlgorithm hash algorithm to use
 * @param issuerCert issuing certificate
 * @param number serial number
 * @param provider provider to use for hashAlgorithm, null if the default one should be used.
 *
 * @exception OCSPException if any problems occur creating the id fields.
 */
public CertificateID(
    String          hashAlgorithm,
    X509Certificate issuerCert,
    BigInteger      number,
    String          provider)
    throws OCSPException
{
    AlgorithmIdentifier hashAlg = new AlgorithmIdentifier(
        new DERObjectIdentifier(hashAlgorithm), DERNull.INSTANCE);

    this.id = createCertID(hashAlg, issuerCert, new ASN1Integer(number), provider);
}
项目:ipack    文件:OtherHash.java   
public AlgorithmIdentifier getHashAlgorithm()
{
    if (null == this.otherHash)
    {
        return new AlgorithmIdentifier(OIWObjectIdentifiers.idSHA1);
    }
    return this.otherHash.getHashAlgorithm();
}
项目:ipack    文件:MacDataGenerator.java   
public MacData build(char[] password, byte[] data)
    throws PKCSException
{
    MacCalculator     macCalculator;

    try
    {
        macCalculator = builder.build(password);

        OutputStream out = macCalculator.getOutputStream();

        out.write(data);

        out.close();
    }
    catch (Exception e)
    {
        throw new PKCSException("unable to process data: " + e.getMessage(), e);
    }

    AlgorithmIdentifier algId = macCalculator.getAlgorithmIdentifier();

    DigestInfo dInfo = new DigestInfo(builder.getDigestAlgorithmIdentifier(), macCalculator.getMac());
    PKCS12PBEParams params = PKCS12PBEParams.getInstance(algId.getParameters());

    return new MacData(dInfo, params.getIV(), params.getIterations().intValue());
}
项目:ipack    文件:X509CertificateObject.java   
private boolean isAlgIdEqual(AlgorithmIdentifier id1, AlgorithmIdentifier id2)
{
    if (!id1.getAlgorithm().equals(id2.getAlgorithm()))
    {
        return false;
    }

    if (id1.getParameters() == null)
    {
        if (id2.getParameters() != null && !id2.getParameters().equals(DERNull.INSTANCE))
        {
            return false;
        }

        return true;
    }

    if (id2.getParameters() == null)
    {
        if (id1.getParameters() != null && !id1.getParameters().equals(DERNull.INSTANCE))
        {
            return false;
        }

        return true;
    }

    return id1.getParameters().equals(id2.getParameters());
}
项目:ipack    文件:EncryptedContentInfo.java   
public EncryptedContentInfo(
    ASN1ObjectIdentifier contentType, 
    AlgorithmIdentifier contentEncryptionAlgorithm,
    ASN1OctetString     encryptedContent)
{
    this.contentType = contentType;
    this.contentEncryptionAlgorithm = contentEncryptionAlgorithm;
    this.encryptedContent = encryptedContent;
}
项目:ipack    文件:EncryptedPrivateKeyInfo.java   
public EncryptedPrivateKeyInfo(
    AlgorithmIdentifier algId,
    byte[]              encoding)
{
    this.algId = algId;
    this.data = new DEROctetString(encoding);
}
项目:xitk    文件:AlgorithmUtil.java   
private static AlgorithmIdentifier getECSigAlgId(HashAlgoType hashAlgo, boolean plainSignature,
        boolean gm) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("hashAlgo", hashAlgo);
    if (gm && plainSignature) {
        throw new IllegalArgumentException("plainSignature and gm cannot be both true");
    }

    ASN1ObjectIdentifier sigAlgOid;

    if (gm) {
        switch (hashAlgo) {
        case SM3:
            sigAlgOid = GMObjectIdentifiers.sm2sign_with_sm3;
            break;
        default:
            throw new NoSuchAlgorithmException("unsupported hash " + hashAlgo +
                    " for SM2 EC key");
        }
    } else if (plainSignature) {
        sigAlgOid = digestToECPlainSigAlgMap.get(hashAlgo);
        if (sigAlgOid == null) {
            throw new NoSuchAlgorithmException(
                    "unsupported hash " + hashAlgo + " for SM2 EC key");
        }
    } else {
        sigAlgOid = digestToECSigAlgMap.get(hashAlgo);
        if (sigAlgOid == null) {
            throw new NoSuchAlgorithmException("unsupported hash " + hashAlgo + " for EC key");
        }
    }

    return new AlgorithmIdentifier(sigAlgOid);
}
项目:ipack    文件:PBMParameter.java   
public PBMParameter(
    byte[] salt,
    AlgorithmIdentifier owf,
    int iterationCount,
    AlgorithmIdentifier mac)
{
    this(new DEROctetString(salt), owf,
         new ASN1Integer(iterationCount), mac);
}
项目:ipack    文件:CompressedData.java   
public CompressedData(
    AlgorithmIdentifier compressionAlgorithm,
    ContentInfo         encapContentInfo)
{
    this.version = new ASN1Integer(0);
    this.compressionAlgorithm = compressionAlgorithm;
    this.encapContentInfo = encapContentInfo;
}
项目:ipack    文件:KeyUtil.java   
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
    try
    {
        return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
    }
    catch (Exception e)
    {
        return null;
    }
}
项目:xitk    文件:P11ECDSAContentSigner.java   
P11ECDSAContentSigner(P11CryptService cryptService, P11EntityIdentifier identityId,
        AlgorithmIdentifier signatureAlgId, boolean plain)
        throws XiSecurityException, P11TokenException {
    this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService);
    this.identityId = ParamUtil.requireNonNull("identityId", identityId);
    this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId);
    try {
        this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded();
    } catch (IOException ex) {
        throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
    }
    this.plain = plain;

    String algOid = signatureAlgId.getAlgorithm().getId();
    HashAlgoType hashAlgo = sigAlgHashMap.get(algOid);
    if (hashAlgo == null) {
        throw new XiSecurityException("unsupported signature algorithm " + algOid);
    }

    P11Slot slot = cryptService.getSlot(identityId.slotId());
    if (slot.supportsMechanism(PKCS11Constants.CKM_ECDSA)) {
        this.mechanism = PKCS11Constants.CKM_ECDSA;
        Digest digest = hashAlgo.createDigest();
        this.outputStream = new DigestOutputStream(digest);
    } else {
        this.mechanism = hashMechMap.get(hashAlgo).longValue();
        if (!slot.supportsMechanism(this.mechanism)) {
            throw new XiSecurityException("unsupported signature algorithm " + algOid);
        }
        this.outputStream = new ByteArrayOutputStream();
    }
}
项目:ipack    文件:KeyUtil.java   
public static byte[] getEncodedSubjectPublicKeyInfo(AlgorithmIdentifier algId, ASN1Encodable keyData)
{
    try
    {
        return getEncodedSubjectPublicKeyInfo(new SubjectPublicKeyInfo(algId, keyData));
    }
    catch (Exception e)
    {
        return null;
    }
}
项目:ipack    文件:JcePasswordAuthenticatedRecipient.java   
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, derivedKey, encryptedContentEncryptionKey);

    final Mac dataMac = helper.createContentMac(secretKey, contentMacAlgorithm);

    return new RecipientOperator(new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentMacAlgorithm;
        }

        public GenericKey getKey()
        {
            return new JceGenericKey(contentMacAlgorithm, secretKey);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(dataMac);
        }

        public byte[] getMac()
        {
            return dataMac.doFinal();
        }
    });
}
项目:ipack    文件:PKMACValue.java   
/**
 * Creates a new PKMACValue.
 * @param aid CMPObjectIdentifiers.passwordBasedMAC, with PBMParameter
 * @param value MAC of the DER-encoded SubjectPublicKeyInfo
 */
public PKMACValue(
    AlgorithmIdentifier aid,
    DERBitString value)
{
    this.algId = aid;
    this.value = value;
}
项目:ipack    文件:MessageImprint.java   
public MessageImprint(
    AlgorithmIdentifier hashAlgorithm,
    byte[]              hashedMessage)
{
    this.hashAlgorithm = hashAlgorithm;
    this.hashedMessage = hashedMessage;
}
项目:xitk    文件:SignerUtil.java   
public static PSSSigner createPSSRSASigner(AlgorithmIdentifier sigAlgId,
        AsymmetricBlockCipher cipher) throws XiSecurityException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
        throw new XiSecurityException("signature algorithm " + sigAlgId.getAlgorithm()
            + " is not allowed");
    }

    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgFromSigAlg(sigAlgId);
    } catch (NoSuchAlgorithmException ex) {
        throw new XiSecurityException(ex.getMessage(), ex);
    }

    RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());

    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier.getInstance(
            param.getMaskGenAlgorithm().getParameters());

    Digest dig = getDigest(digAlgId);
    Digest mfgDig = getDigest(mfgDigAlgId);

    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();
    AsymmetricBlockCipher tmpCipher = (cipher == null) ? new RSABlindedEngine() : cipher;

    return new PSSSigner(tmpCipher, dig, mfgDig, saltSize, getTrailer(trailerField));
}