Code example for OAEPParameterSpec

Methods: getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource

0
OAEPParameterSpec spec = (OAEPParameterSpec)params;
                 
                paramSpec = params;
                 
                if (!spec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !spec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
                { 
                    throw new InvalidAlgorithmParameterException("unknown mask generation function specified");
                } 
                 
                if (!(spec.getMGFParameters() instanceof MGF1ParameterSpec))
                { 
                    throw new InvalidAlgorithmParameterException("unkown MGF parameters");
                } 
     
                Digest digest = DigestFactory.getDigest(spec.getDigestAlgorithm());
 
                if (digest == null)
                { 
                    throw new InvalidAlgorithmParameterException("no match on digest algorithm: "+ spec.getDigestAlgorithm());
                } 
 
                MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)spec.getMGFParameters();
                Digest mgfDigest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
                 
                if (mgfDigest == null)
                { 
                    throw new InvalidAlgorithmParameterException("no match on MGF digest algorithm: "+ mgfParams.getDigestAlgorithm());
                } 
                 
                cipher = new OAEPEncoding(new RSABlindedEngine(), digest, mgfDigest, ((PSource.PSpecified)spec.getPSource()).getValue());
            } 
        } 
        else 
        { 
            throw new IllegalArgumentException("unknown parameter type.");