⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdkalgorithmparameters.java

📁 kmlnjlkj nlkjlkjkljl okopokipoipo oipipipo i
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            {                return elP.getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Error encoding ElGamalParameters");            }        }        protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                return engineGetEncoded();            }            return null;        }        protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == ElGamalParameterSpec.class)            {                return currentSpec;            }            else if (paramSpec == DHParameterSpec.class)            {                return new DHParameterSpec(currentSpec.getP(), currentSpec.getG());            }            throw new InvalidParameterSpecException("unknown parameter spec passed to ElGamal parameters object.");        }        protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof ElGamalParameterSpec) && !(paramSpec instanceof DHParameterSpec))            {                throw new InvalidParameterSpecException("DHParameterSpec required to initialise a ElGamal algorithm parameters object");            }            if (paramSpec instanceof ElGamalParameterSpec)            {                this.currentSpec = (ElGamalParameterSpec)paramSpec;            }            else            {                DHParameterSpec s = (DHParameterSpec)paramSpec;                                this.currentSpec = new ElGamalParameterSpec(s.getP(), s.getG());            }        }        protected void engineInit(            byte[] params)             throws IOException        {            try            {                ElGamalParameter elP = new ElGamalParameter((ASN1Sequence)ASN1Object.fromByteArray(params));                currentSpec = new ElGamalParameterSpec(elP.getP(), elP.getG());            }            catch (ClassCastException e)            {                throw new IOException("Not a valid ElGamal Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid ElGamal Parameter encoding.");            }        }        protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                engineInit(params);            }            else            {                throw new IOException("Unknown parameter format " + format);            }        }        protected String engineToString()         {            return "ElGamal Parameters";        }    }    public static class IES        extends JDKAlgorithmParameters    {        IESParameterSpec     currentSpec;        /**         * in the absence of a standard way of doing it this will do for         * now...         */        protected byte[] engineGetEncoded()         {            try            {                ASN1EncodableVector v = new ASN1EncodableVector();                v.add(new DEROctetString(currentSpec.getDerivationV()));                v.add(new DEROctetString(currentSpec.getEncodingV()));                v.add(new DERInteger(currentSpec.getMacKeySize()));                return new DERSequence(v).getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Error encoding IESParameters");            }        }        protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                return engineGetEncoded();            }            return null;        }        protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == IESParameterSpec.class)            {                return currentSpec;            }            throw new InvalidParameterSpecException("unknown parameter spec passed to ElGamal parameters object.");        }        protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof IESParameterSpec))            {                throw new InvalidParameterSpecException("IESParameterSpec required to initialise a IES algorithm parameters object");            }            this.currentSpec = (IESParameterSpec)paramSpec;        }        protected void engineInit(            byte[] params)             throws IOException        {            try            {                ASN1Sequence s = (ASN1Sequence)ASN1Object.fromByteArray(params);                this.currentSpec = new IESParameterSpec(                                        ((ASN1OctetString)s.getObjectAt(0)).getOctets(),                                        ((ASN1OctetString)s.getObjectAt(0)).getOctets(),                                        ((DERInteger)s.getObjectAt(0)).getValue().intValue());            }            catch (ClassCastException e)            {                throw new IOException("Not a valid IES Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid IES Parameter encoding.");            }        }        protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                engineInit(params);            }            else            {                throw new IOException("Unknown parameter format " + format);            }        }        protected String engineToString()         {            return "IES Parameters";        }    }        public static class OAEP        extends JDKAlgorithmParameters    {        OAEPParameterSpec     currentSpec;            /**         * Return the PKCS#1 ASN.1 structure RSAES-OAEP-params.         */        protected byte[] engineGetEncoded()         {            AlgorithmIdentifier     hashAlgorithm = new AlgorithmIdentifier(                                                            JCEDigestUtil.getOID(currentSpec.getDigestAlgorithm()),                                                            new DERNull());            MGF1ParameterSpec       mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();            AlgorithmIdentifier     maskGenAlgorithm = new AlgorithmIdentifier(                                                            PKCSObjectIdentifiers.id_mgf1,                                                             new AlgorithmIdentifier(JCEDigestUtil.getOID(mgfSpec.getDigestAlgorithm()), new DERNull()));            PSource.PSpecified      pSource = (PSource.PSpecified)currentSpec.getPSource();            AlgorithmIdentifier     pSourceAlgorithm = new AlgorithmIdentifier(                                                            PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));            RSAESOAEPparams         oaepP = new RSAESOAEPparams(hashAlgorithm, maskGenAlgorithm, pSourceAlgorithm);                try            {                return oaepP.getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Error encoding OAEPParameters");            }        }            protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                return engineGetEncoded();            }                return null;        }            protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == OAEPParameterSpec.class && currentSpec != null)            {                return currentSpec;            }                throw new InvalidParameterSpecException("unknown parameter spec passed to OAEP parameters object.");        }            protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof OAEPParameterSpec))            {                throw new InvalidParameterSpecException("OAEPParameterSpec required to initialise an OAEP algorithm parameters object");            }                this.currentSpec = (OAEPParameterSpec)paramSpec;        }            protected void engineInit(            byte[] params)             throws IOException        {            try            {                RSAESOAEPparams oaepP = new RSAESOAEPparams((ASN1Sequence)ASN1Object.fromByteArray(params));                currentSpec = new OAEPParameterSpec(                                       oaepP.getHashAlgorithm().getObjectId().getId(),                                        oaepP.getMaskGenAlgorithm().getObjectId().getId(),                                        new MGF1ParameterSpec(AlgorithmIdentifier.getInstance(oaepP.getMaskGenAlgorithm().getParameters()).getObjectId().getId()),                                       new PSource.PSpecified(ASN1OctetString.getInstance(oaepP.getPSourceAlgorithm().getParameters()).getOctets()));            }            catch (ClassCastException e)            {                throw new IOException("Not a valid OAEP Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid OAEP Parameter encoding.");            }        }            protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (format.equalsIgnoreCase("X.509")                    || format.equalsIgnoreCase("ASN.1"))            {                engineInit(params);            }            else            {                throw new IOException("Unknown parameter format " + format);            }        }            protected String engineToString()         {            return "OAEP Parameters";        }    }        public static class PSS        extends JDKAlgorithmParameters    {          PSSParameterSpec     currentSpec;            /**         * Return the PKCS#1 ASN.1 structure RSASSA-PSS-params.         */        protected byte[] engineGetEncoded()             throws IOException        {            PSSParameterSpec    pssSpec = currentSpec;            AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(                                                JCEDigestUtil.getOID(pssSpec.getDigestAlgorithm()),                                                new DERNull());            MGF1ParameterSpec   mgfSpec = (MGF1ParameterSpec)pssSpec.getMGFParameters();            AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(                                                PKCSObjectIdentifiers.id_mgf1,                                                 new AlgorithmIdentifier(JCEDigestUtil.getOID(mgfSpec.getDigestAlgorithm()), new DERNull()));            RSASSAPSSparams     pssP = new RSASSAPSSparams(hashAlgorithm, maskGenAlgorithm, new DERInteger(pssSpec.getSaltLength()), new DERInteger(pssSpec.getTrailerField()));                        return pssP.getEncoded("DER");        }            protected byte[] engineGetEncoded(            String format)             throws IOException        {            if (format.equalsIgnoreCase("X.509")                    || format.equalsIgnoreCase("ASN.1"))            {                return engineGetEncoded();            }                return null;        }            protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == PSSParameterSpec.class && currentSpec != null)            {                return currentSpec;            }                throw new InvalidParameterSpecException("unknown parameter spec passed to PSS parameters object.");        }            protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof PSSParameterSpec))            {                throw new InvalidParameterSpecException("PSSParameterSpec required to initialise an PSS algorithm parameters object");            }                this.currentSpec = (PSSParameterSpec)paramSpec;        }            protected void engineInit(            byte[] params)             throws IOException        {            try            {                RSASSAPSSparams pssP = new RSASSAPSSparams((ASN1Sequence)ASN1Object.fromByteArray(params));                currentSpec = new PSSParameterSpec(                                       pssP.getHashAlgorithm().getObjectId().getId(),                                        pssP.getMaskGenAlgorithm().getObjectId().getId(),                                        new MGF1ParameterSpec(AlgorithmIdentifier.getInstance(pssP.getMaskGenAlgorithm().getParameters()).getObjectId().getId()),                                       pssP.getSaltLength().getValue().intValue(),                                       pssP.getTrailerField().getValue().intValue());            }            catch (ClassCastException e)            {                throw new IOException("Not a valid PSS Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid PSS Parameter encoding.");            }        }            protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (isASN1FormatString(format) || format.equalsIgnoreCase("X.509"))            {                engineInit(params);            }            else            {                throw new IOException("Unknown parameter format " + format);            }        }            protected String engineToString()         {            return "PSS Parameters";        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -