Java Code Examples for java.security.spec.MGF1ParameterSpec#getDigestAlgorithm()

The following examples show how to use java.security.spec.MGF1ParameterSpec#getDigestAlgorithm() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestOAEPParameterSpec.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 2
Source File: TestOAEPParameterSpec.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 3
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 4
Source File: TestOAEPParameterSpec.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 5
Source File: TestOAEPParameterSpec.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 6
Source File: TestOAEPParameterSpec.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 7
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 8
Source File: TestOAEPParameterSpec.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 9
Source File: TestOAEPParameterSpec.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean compareMGF(OAEPParameterSpec s1,
    OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec)s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec)s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
 
Example 10
Source File: CipherSpi.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private void initFromSpec(
    OAEPParameterSpec pSpec) 
    throws NoSuchPaddingException
{
    MGF1ParameterSpec   mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest              digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new BufferedAsymmetricBlockCipher(new OAEPEncoding(new ElGamalEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue()));        
    paramSpec = pSpec;
}
 
Example 11
Source File: RsaUsingShaAlgorithm.java    From Jose4j with Apache License 2.0 5 votes vote down vote up
public RsaPssSha512()
{
    super(AlgorithmIdentifiers.RSA_PSS_USING_SHA512, "SHA512withRSAandMGF1");
    MGF1ParameterSpec mgf1pec = MGF1ParameterSpec.SHA512;
    PSSParameterSpec pssSpec = new PSSParameterSpec(mgf1pec.getDigestAlgorithm(), MGF1, mgf1pec, 64, TRAILER);
    setAlgorithmParameterSpec(pssSpec);
}
 
Example 12
Source File: RsaUsingShaAlgorithm.java    From Jose4j with Apache License 2.0 5 votes vote down vote up
public RsaPssSha384()
{
    super(AlgorithmIdentifiers.RSA_PSS_USING_SHA384, "SHA384withRSAandMGF1");
    MGF1ParameterSpec mgf1pec = MGF1ParameterSpec.SHA384;
    PSSParameterSpec pssSpec = new PSSParameterSpec(mgf1pec.getDigestAlgorithm(), MGF1, mgf1pec, 48, TRAILER);
    setAlgorithmParameterSpec(pssSpec);
}
 
Example 13
Source File: RsaUsingShaAlgorithm.java    From Jose4j with Apache License 2.0 5 votes vote down vote up
public RsaPssSha256()
{
    super(AlgorithmIdentifiers.RSA_PSS_USING_SHA256, "SHA256withRSAandMGF1");
    MGF1ParameterSpec mgf1pec = MGF1ParameterSpec.SHA256;
    PSSParameterSpec pssSpec = new PSSParameterSpec(mgf1pec.getDigestAlgorithm(), MGF1, mgf1pec, 32, TRAILER);
    setAlgorithmParameterSpec(pssSpec);
}
 
Example 14
Source File: CipherSpi.java    From ripple-lib-java with ISC License 5 votes vote down vote up
private void initFromSpec(
    OAEPParameterSpec pSpec) 
    throws NoSuchPaddingException
{
    MGF1ParameterSpec   mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest              digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new BufferedAsymmetricBlockCipher(new OAEPEncoding(new ElGamalEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue()));        
    paramSpec = pSpec;
}
 
Example 15
Source File: CipherSpi.java    From ripple-lib-java with ISC License 5 votes vote down vote up
private void initFromSpec(
    OAEPParameterSpec pSpec)
    throws NoSuchPaddingException
{
    MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new OAEPEncoding(new RSABlindedEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue());
    paramSpec = pSpec;
}
 
Example 16
Source File: PSSParameters.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the encoding of a {@link PSSParameterSpec} object. This method
 * is used in this class and {@link AlgorithmId}.
 *
 * @param spec a {@code PSSParameterSpec} object
 * @return its DER encoding
 * @throws IOException if the name of a MessageDigest or MaskGenAlgorithm
 *          is unsupported
 */
public static byte[] getEncoded(PSSParameterSpec spec) throws IOException {

    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if (!(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new IOException("Cannot encode " + mgfSpec);
    }

    MGF1ParameterSpec mgf1Spec = (MGF1ParameterSpec)mgfSpec;

    DerOutputStream tmp = new DerOutputStream();
    DerOutputStream tmp2, tmp3;

    // MD
    AlgorithmId mdAlgId;
    try {
        mdAlgId = AlgorithmId.get(spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new IOException("AlgorithmId " + spec.getDigestAlgorithm() +
                " impl not found");
    }
    if (!mdAlgId.getOID().equals(AlgorithmId.SHA_oid)) {
        tmp2 = new DerOutputStream();
        mdAlgId.derEncode(tmp2);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0),
                tmp2);
    }

    // MGF
    AlgorithmId mgfDigestId;
    try {
        mgfDigestId = AlgorithmId.get(mgf1Spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException nase) {
        throw new IOException("AlgorithmId " +
                mgf1Spec.getDigestAlgorithm() + " impl not found");
    }

    if (!mgfDigestId.getOID().equals(AlgorithmId.SHA_oid)) {
        tmp2 = new DerOutputStream();
        tmp2.putOID(AlgorithmId.mgf1_oid);
        mgfDigestId.encode(tmp2);
        tmp3 = new DerOutputStream();
        tmp3.write(DerValue.tag_Sequence, tmp2);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1),
                tmp3);
    }

    // SaltLength
    if (spec.getSaltLength() != 20) {
        tmp2 = new DerOutputStream();
        tmp2.putInteger(spec.getSaltLength());
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 2),
                tmp2);
    }

    // TrailerField
    if (spec.getTrailerField() != PSSParameterSpec.TRAILER_FIELD_BC) {
        tmp2 = new DerOutputStream();
        tmp2.putInteger(spec.getTrailerField());
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 3),
                tmp2);
    }

    // Put all together under a SEQUENCE tag
    DerOutputStream out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, tmp);
    return out.toByteArray();
}
 
Example 17
Source File: P11RSAPSSSignatureSpi.java    From xipki with Apache License 2.0 4 votes vote down vote up
@Override
protected void engineSetParameter(AlgorithmParameterSpec params)
    throws InvalidParameterException {
  if (params instanceof PSSParameterSpec) {
    PSSParameterSpec newParamSpec = (PSSParameterSpec) params;

    if (originalSpec != null) {
      if (!DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(),
          newParamSpec.getDigestAlgorithm())) {
        throw new InvalidParameterException("parameter must be using "
            + originalSpec.getDigestAlgorithm());
      }
    }
    if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1")
        && !newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId())) {
      throw new InvalidParameterException("unknown mask generation function specified");
    }

    if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec)) {
      throw new InvalidParameterException("unkown MGF parameters");
    }

    MGF1ParameterSpec mgfParams = (MGF1ParameterSpec) newParamSpec.getMGFParameters();

    if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(),
        newParamSpec.getDigestAlgorithm())) {
      throw new InvalidParameterException(
          "digest algorithm for MGF should be the same as for PSS parameters.");
    }

    Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());

    if (newDigest == null) {
      throw new InvalidParameterException(
          "no match on MGF digest algorithm: " + mgfParams.getDigestAlgorithm());
    }

    this.engineParams = null;
    this.paramSpec = newParamSpec;
    this.mgfDigest = newDigest;
    this.saltLength = paramSpec.getSaltLength();
    this.trailer = getTrailer(paramSpec.getTrailerField());

    setupContentDigest();
  } else {
    throw new InvalidParameterException("only PSSParameterSpec supported");
  }
}
 
Example 18
Source File: PSSParameters.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the encoding of a {@link PSSParameterSpec} object. This method
 * is used in this class and {@link AlgorithmId}.
 *
 * @param spec a {@code PSSParameterSpec} object
 * @return its DER encoding
 * @throws IOException if the name of a MessageDigest or MaskGenAlgorithm
 *          is unsupported
 */
public static byte[] getEncoded(PSSParameterSpec spec) throws IOException {

    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if (!(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new IOException("Cannot encode " + mgfSpec);
    }

    MGF1ParameterSpec mgf1Spec = (MGF1ParameterSpec)mgfSpec;

    DerOutputStream tmp = new DerOutputStream();
    DerOutputStream tmp2, tmp3;

    // MD
    AlgorithmId mdAlgId;
    try {
        mdAlgId = AlgorithmId.get(spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException nsae) {
        throw new IOException("AlgorithmId " + spec.getDigestAlgorithm() +
                " impl not found");
    }
    if (!mdAlgId.getOID().equals(AlgorithmId.SHA_oid)) {
        tmp2 = new DerOutputStream();
        mdAlgId.derEncode(tmp2);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0),
                tmp2);
    }

    // MGF
    AlgorithmId mgfDigestId;
    try {
        mgfDigestId = AlgorithmId.get(mgf1Spec.getDigestAlgorithm());
    } catch (NoSuchAlgorithmException nase) {
        throw new IOException("AlgorithmId " +
                mgf1Spec.getDigestAlgorithm() + " impl not found");
    }

    if (!mgfDigestId.getOID().equals(AlgorithmId.SHA_oid)) {
        tmp2 = new DerOutputStream();
        tmp2.putOID(AlgorithmId.mgf1_oid);
        mgfDigestId.encode(tmp2);
        tmp3 = new DerOutputStream();
        tmp3.write(DerValue.tag_Sequence, tmp2);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1),
                tmp3);
    }

    // SaltLength
    if (spec.getSaltLength() != 20) {
        tmp2 = new DerOutputStream();
        tmp2.putInteger(spec.getSaltLength());
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 2),
                tmp2);
    }

    // TrailerField
    if (spec.getTrailerField() != PSSParameterSpec.TRAILER_FIELD_BC) {
        tmp2 = new DerOutputStream();
        tmp2.putInteger(spec.getTrailerField());
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 3),
                tmp2);
    }

    // Put all together under a SEQUENCE tag
    DerOutputStream out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, tmp);
    return out.toByteArray();
}
 
Example 19
Source File: PSSSignatureSpi.java    From ripple-lib-java with ISC License 4 votes vote down vote up
protected void engineSetParameter(
    AlgorithmParameterSpec params)
    throws InvalidParameterException
{
    if (params instanceof PSSParameterSpec)
    {
        PSSParameterSpec newParamSpec = (PSSParameterSpec)params;
        
        if (originalSpec != null)
        {
            if (!DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
            {
                throw new InvalidParameterException("parameter must be using " + originalSpec.getDigestAlgorithm());
            }
        }
        if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
        {
            throw new InvalidParameterException("unknown mask generation function specified");
        }
        
        if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec))
        {
            throw new InvalidParameterException("unkown MGF parameters");
        }
        
        MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)newParamSpec.getMGFParameters();
        
        if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
        {
            throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
        }
        
        Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
        
        if (newDigest == null)
        {
            throw new InvalidParameterException("no match on MGF digest algorithm: "+ mgfParams.getDigestAlgorithm());
        }

        this.engineParams = null;
        this.paramSpec = newParamSpec;
        this.mgfDigest = newDigest;
        this.saltLength = paramSpec.getSaltLength();
        this.trailer = getTrailer(paramSpec.getTrailerField());

        setupContentDigest();
    }
    else
    {
        throw new InvalidParameterException("Only PSSParameterSpec supported");
    }
}
 
Example 20
Source File: PSSSignatureSpi.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
protected void engineSetParameter(
    AlgorithmParameterSpec params)
    throws InvalidParameterException
{
    if (params instanceof PSSParameterSpec)
    {
        PSSParameterSpec newParamSpec = (PSSParameterSpec)params;
        
        if (originalSpec != null)
        {
            if (!DigestFactory.isSameDigest(originalSpec.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
            {
                throw new InvalidParameterException("parameter must be using " + originalSpec.getDigestAlgorithm());
            }
        }
        if (!newParamSpec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !newParamSpec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
        {
            throw new InvalidParameterException("unknown mask generation function specified");
        }
        
        if (!(newParamSpec.getMGFParameters() instanceof MGF1ParameterSpec))
        {
            throw new InvalidParameterException("unkown MGF parameters");
        }
        
        MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)newParamSpec.getMGFParameters();
        
        if (!DigestFactory.isSameDigest(mgfParams.getDigestAlgorithm(), newParamSpec.getDigestAlgorithm()))
        {
            throw new InvalidParameterException("digest algorithm for MGF should be the same as for PSS parameters.");
        }
        
        Digest newDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
        
        if (newDigest == null)
        {
            throw new InvalidParameterException("no match on MGF digest algorithm: "+ mgfParams.getDigestAlgorithm());
        }

        this.engineParams = null;
        this.paramSpec = newParamSpec;
        this.mgfDigest = newDigest;
        this.saltLength = paramSpec.getSaltLength();
        this.trailer = getTrailer(paramSpec.getTrailerField());

        setupContentDigest();
    }
    else
    {
        throw new InvalidParameterException("Only PSSParameterSpec supported");
    }
}