Example usage for org.bouncycastle.asn1.pkcs RSASSAPSSparams getInstance

List of usage examples for org.bouncycastle.asn1.pkcs RSASSAPSSparams getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.pkcs RSASSAPSSparams getInstance.

Prototype

public static RSASSAPSSparams getInstance(Object obj) 

Source Link

Usage

From source file:org.xipki.common.util.AlgorithmUtil.java

License:Open Source License

static public String getSignatureAlgoName(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();

    if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) {
        return "SHA1withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) {
        return "SHA224withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) {
        return "SHA256withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) {
        return "SHA384withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) {
        return "SHA512WITHECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) {
        return "SHA1WITHPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) {
        return "SHA224WITHPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) {
        return "SHA256WITHPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) {
        return "SHA384WITHPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) {
        return "SHA512WITHPLAIN-ECDSA";
    } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
        return "SHA1withDSA";
    } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
        return "SHA1withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) {
        return "SHA224withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) {
        return "SHA256withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) {
        return "SHA384withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) {
        return "SHA512withDSA";
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        return "SHA1withRSA";
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        return "SHA224withRSA";
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        return "SHA256withRSA";
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        return "SHA384withRSA";
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        return "SHA512withRSA";
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) {
            return "SHA1withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) {
            return "SHA256withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) {
            return "SHA384withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) {
            return "SHA512withRSAandMGF1";
        } else {//from  ww  w  .j a v  a2s .  c o m
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid.getId());
        }
    } else {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId());
    }
}

From source file:org.xipki.common.util.AlgorithmUtil.java

License:Open Source License

static public AlgorithmIdentifier extractDigesetAlgorithmIdentifier(final AlgorithmIdentifier sigAlgId)
        throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();

    ASN1ObjectIdentifier digestAlgOid;//from ww  w . j  av a  2s.  co  m
    if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        ASN1Encodable asn1Encodable = sigAlgId.getParameters();
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId());
    }

    return new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE);
}

From source file:org.xipki.commons.security.pkcs11.P11RSAPSSContentSigner.java

License:Open Source License

P11RSAPSSContentSigner(final P11CryptService cryptService, final P11EntityIdentifier identityId,
        final AlgorithmIdentifier signatureAlgId, final SecureRandom random)
        throws XiSecurityException, P11TokenException {
    this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService);
    this.identityId = ParamUtil.requireNonNull("identityId", identityId);
    this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId);
    ParamUtil.requireNonNull("random", random);

    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(signatureAlgId.getAlgorithm())) {
        throw new XiSecurityException("unsupported signature algorithm " + signatureAlgId.getAlgorithm());
    }/*from w ww  . java 2 s . c  om*/

    RSASSAPSSparams asn1Params = RSASSAPSSparams.getInstance(signatureAlgId.getParameters());
    ASN1ObjectIdentifier digestAlgOid = asn1Params.getHashAlgorithm().getAlgorithm();
    HashAlgoType hashAlgo = HashAlgoType.getHashAlgoType(digestAlgOid);
    if (hashAlgo == null) {
        throw new XiSecurityException("unsupported hash algorithm " + digestAlgOid.getId());
    }

    P11SlotIdentifier slotId = identityId.getSlotId();
    P11Slot slot = cryptService.getSlot(slotId);
    if (slot.supportsMechanism(P11Constants.CKM_RSA_PKCS_PSS)) {
        this.mechanism = P11Constants.CKM_RSA_PKCS_PSS;
        this.parameters = new P11RSAPkcsPssParams(asn1Params);
        Digest digest = SignerUtil.getDigest(hashAlgo);
        this.outputStream = new DigestOutputStream(digest);
    } else if (slot.supportsMechanism(P11Constants.CKM_RSA_X_509)) {
        this.mechanism = P11Constants.CKM_RSA_X_509;
        this.parameters = null;
        AsymmetricBlockCipher cipher = new P11PlainRSASigner();
        P11RSAKeyParameter keyParam;
        try {
            keyParam = P11RSAKeyParameter.getInstance(cryptService, identityId);
        } catch (InvalidKeyException ex) {
            throw new XiSecurityException(ex.getMessage(), ex);
        }
        PSSSigner pssSigner = SignerUtil.createPSSRSASigner(signatureAlgId, cipher);
        pssSigner.init(true, new ParametersWithRandom(keyParam, random));
        this.outputStream = new PSSSignerOutputStream(pssSigner);
    } else {
        switch (hashAlgo) {
        case SHA1:
            this.mechanism = P11Constants.CKM_SHA1_RSA_PKCS_PSS;
            break;
        case SHA224:
            this.mechanism = P11Constants.CKM_SHA224_RSA_PKCS_PSS;
            break;
        case SHA256:
            this.mechanism = P11Constants.CKM_SHA256_RSA_PKCS_PSS;
            break;
        case SHA384:
            this.mechanism = P11Constants.CKM_SHA384_RSA_PKCS_PSS;
            break;
        case SHA512:
            this.mechanism = P11Constants.CKM_SHA512_RSA_PKCS_PSS;
            break;
        case SHA3_224:
            this.mechanism = P11Constants.CKM_SHA3_224_RSA_PKCS_PSS;
            break;
        case SHA3_256:
            this.mechanism = P11Constants.CKM_SHA3_256_RSA_PKCS_PSS;
            break;
        case SHA3_384:
            this.mechanism = P11Constants.CKM_SHA3_384_RSA_PKCS_PSS;
            break;
        case SHA3_512:
            this.mechanism = P11Constants.CKM_SHA3_512_RSA_PKCS_PSS;
            break;
        default:
            throw new RuntimeException("should not reach here, unknown HashAlgoType " + hashAlgo);
        }

        if (!slot.supportsMechanism(this.mechanism)) {
            throw new XiSecurityException("unsupported signature algorithm "
                    + PKCSObjectIdentifiers.id_RSASSA_PSS.getId() + " with " + hashAlgo);
        }

        this.parameters = new P11RSAPkcsPssParams(asn1Params);
        this.outputStream = new ByteArrayOutputStream();
    }
}

From source file:org.xipki.commons.security.util.AlgorithmUtil.java

License:Open Source License

public static String getSignatureAlgoName(final AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();

    if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) {
        return "SHA1withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) {
        return "SHA224withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) {
        return "SHA256withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) {
        return "SHA384withECDSA";
    } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) {
        return "SHA512withECDSA";
    } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_224.equals(algOid)) {
        return "SHA3-224withECDSA";
    } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_256.equals(algOid)) {
        return "SHA3-256withECDSA";
    } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_384.equals(algOid)) {
        return "SHA3-384withECDSA";
    } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_512.equals(algOid)) {
        return "SHA3-512withECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) {
        return "SHA1withPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) {
        return "SHA224withPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) {
        return "SHA256withPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) {
        return "SHA384withPLAIN-ECDSA";
    } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) {
        return "SHA512withPLAIN-ECDSA";
    } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
        return "SHA1withDSA";
    } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
        return "SHA1withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) {
        return "SHA224withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) {
        return "SHA256withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) {
        return "SHA384withDSA";
    } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) {
        return "SHA512withDSA";
    } else if (NISTObjectIdentifiers.id_dsa_with_sha3_224.equals(algOid)) {
        return "SHA3-224withDSA";
    } else if (NISTObjectIdentifiers.id_dsa_with_sha3_256.equals(algOid)) {
        return "SHA3-256withDSA";
    } else if (NISTObjectIdentifiers.id_dsa_with_sha3_384.equals(algOid)) {
        return "SHA3-384withDSA";
    } else if (NISTObjectIdentifiers.id_dsa_with_sha3_512.equals(algOid)) {
        return "SHA3-512withDSA";
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        return "SHA1withRSA";
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        return "SHA224withRSA";
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        return "SHA256withRSA";
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        return "SHA384withRSA";
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        return "SHA512withRSA";
    } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224.equals(algOid)) {
        return "SHA3-224withRSA";
    } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256.equals(algOid)) {
        return "SHA3-256withRSA";
    } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384.equals(algOid)) {
        return "SHA3-384withRSA";
    } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512.equals(algOid)) {
        return "SHA3-512withRSA";
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        if (X509ObjectIdentifiers.id_SHA1.equals(digestAlgOid)) {
            return "SHA1withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha256.equals(digestAlgOid)) {
            return "SHA256withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha384.equals(digestAlgOid)) {
            return "SHA384withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha512.equals(digestAlgOid)) {
            return "SHA512withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha3_224.equals(digestAlgOid)) {
            return "SHA3-224withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha3_256.equals(digestAlgOid)) {
            return "SHA3-256withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha3_384.equals(digestAlgOid)) {
            return "SHA3-384withRSAandMGF1";
        } else if (NISTObjectIdentifiers.id_sha3_512.equals(digestAlgOid)) {
            return "SHA3-512withRSAandMGF1";
        } else {/*from  w w  w .  j  a  va2s.c  o  m*/
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid.getId());
        }
    } else {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + algOid.getId());
    }
}

From source file:org.xipki.commons.security.util.AlgorithmUtil.java

License:Open Source License

public static AlgorithmIdentifier extractDigesetAlgId(final AlgorithmIdentifier sigAlgId)
        throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();

    ASN1ObjectIdentifier digestAlgOid;/*from  ww w. j  a v a  2 s.c  o m*/
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        ASN1Encodable asn1Encodable = sigAlgId.getParameters();
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        HashAlgoType digestAlg;

        if (X9ObjectIdentifiers.ecdsa_with_SHA1.equals(algOid)) {
            digestAlg = HashAlgoType.SHA1;
        } else if (X9ObjectIdentifiers.ecdsa_with_SHA224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA224;
        } else if (X9ObjectIdentifiers.ecdsa_with_SHA256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA256;
        } else if (X9ObjectIdentifiers.ecdsa_with_SHA384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA384;
        } else if (X9ObjectIdentifiers.ecdsa_with_SHA512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA512;
        } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_224;
        } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_256;
        } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_384;
        } else if (NISTObjectIdentifiers.id_ecdsa_with_sha3_512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_512;
        } else if (BSIObjectIdentifiers.ecdsa_plain_SHA1.equals(algOid)) {
            digestAlg = HashAlgoType.SHA1;
        } else if (BSIObjectIdentifiers.ecdsa_plain_SHA224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA224;
        } else if (BSIObjectIdentifiers.ecdsa_plain_SHA256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA256;
        } else if (BSIObjectIdentifiers.ecdsa_plain_SHA384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA384;
        } else if (BSIObjectIdentifiers.ecdsa_plain_SHA512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA512;
        } else if (X9ObjectIdentifiers.id_dsa_with_sha1.equals(algOid)) {
            digestAlg = HashAlgoType.SHA1;
        } else if (NISTObjectIdentifiers.dsa_with_sha224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA224;
        } else if (NISTObjectIdentifiers.dsa_with_sha256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA256;
        } else if (NISTObjectIdentifiers.dsa_with_sha384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA384;
        } else if (NISTObjectIdentifiers.dsa_with_sha512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA512;
        } else if (NISTObjectIdentifiers.id_dsa_with_sha3_224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_224;
        } else if (NISTObjectIdentifiers.id_dsa_with_sha3_256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_256;
        } else if (NISTObjectIdentifiers.id_dsa_with_sha3_384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_384;
        } else if (NISTObjectIdentifiers.id_dsa_with_sha3_512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_512;
        } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
            digestAlg = HashAlgoType.SHA1;
        } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
            digestAlg = HashAlgoType.SHA224;
        } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
            digestAlg = HashAlgoType.SHA256;
        } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
            digestAlg = HashAlgoType.SHA384;
        } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
            digestAlg = HashAlgoType.SHA512;
        } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_224.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_224;
        } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_256.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_256;
        } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_384.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_384;
        } else if (NISTObjectIdentifiers.id_rsassa_pkcs1_v1_5_with_sha3_512.equals(algOid)) {
            digestAlg = HashAlgoType.SHA3_512;
        } else {
            throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId());
        }

        digestAlgOid = digestAlg.getOid();
    }

    return new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE);
}

From source file:org.xipki.commons.security.util.SignerUtil.java

License:Open Source License

public static PSSSigner createPSSRSASigner(final AlgorithmIdentifier sigAlgId,
        final 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");
    }/*w w w  . j  av  a2s .  com*/

    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgId(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));
}

From source file:org.xipki.ocsp.server.impl.ResponderSigner.java

License:Open Source License

private static String getSignatureAlgorithmName(final AlgorithmIdentifier sigAlgId) {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid) == false) {
        return algOid.getId();
    }//from w  w w.  j  ava  2 s  .  c om

    ASN1Encodable asn1Encodable = sigAlgId.getParameters();
    RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
    ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    return digestAlgOid.getId() + "WITHRSAANDMGF1";
}

From source file:org.xipki.pki.ocsp.server.impl.ResponderSigner.java

License:Open Source License

private static String getSignatureAlgorithmName(final AlgorithmIdentifier sigAlgId) {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        return algOid.getId();
    }//from  w w  w . j  a  v  a  2s.co  m

    ASN1Encodable asn1Encodable = sigAlgId.getParameters();
    RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
    ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    return digestAlgOid.getId() + "WITHRSAANDMGF1";
}

From source file:org.xipki.pki.scep.util.ScepUtil.java

License:Open Source License

public static ASN1ObjectIdentifier extractDigesetAlgorithmIdentifier(final String sigOid,
        final byte[] sigParams) throws NoSuchAlgorithmException {
    ParamUtil.requireNonBlank("sigOid", sigOid);

    ASN1ObjectIdentifier algOid = new ASN1ObjectIdentifier(sigOid);

    ASN1ObjectIdentifier digestAlgOid;//from   w  w w.  j  av  a2s. c  o m
    if (PKCSObjectIdentifiers.md5WithRSAEncryption.equals(algOid)) {
        digestAlgOid = PKCSObjectIdentifiers.md5;
    } else if (PKCSObjectIdentifiers.sha1WithRSAEncryption.equals(algOid)) {
        digestAlgOid = X509ObjectIdentifiers.id_SHA1;
    } else if (PKCSObjectIdentifiers.sha224WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha224;
    } else if (PKCSObjectIdentifiers.sha256WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha256;
    } else if (PKCSObjectIdentifiers.sha384WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha384;
    } else if (PKCSObjectIdentifiers.sha512WithRSAEncryption.equals(algOid)) {
        digestAlgOid = NISTObjectIdentifiers.id_sha512;
    } else if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigParams);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        throw new NoSuchAlgorithmException("unknown signature algorithm" + algOid.getId());
    }

    return digestAlgOid;
}

From source file:org.xipki.security.SignerUtil.java

License:Open Source License

static public PSSSigner createPSSRSASigner(final AlgorithmIdentifier sigAlgId, AsymmetricBlockCipher cipher)
        throws OperatorCreationException {
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm()) == false) {
        throw new OperatorCreationException(
                "signature algorithm " + sigAlgId.getAlgorithm() + " is not allowed");
    }/*w w  w  . j a v a 2  s  .com*/

    BcDigestProvider digestProvider = BcDefaultDigestProvider.INSTANCE;
    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgorithmIdentifier(sigAlgId);
    } catch (NoSuchAlgorithmException e) {
        throw new OperatorCreationException(e.getMessage(), e);
    }
    Digest dig = digestProvider.get(digAlgId);
    if (cipher == null) {
        cipher = new RSABlindedEngine();
    }

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

    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier
            .getInstance(param.getMaskGenAlgorithm().getParameters());
    Digest mfgDig = digestProvider.get(mfgDigAlgId);

    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();

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