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

📄 jdkalgorithmparameters.java

📁 kmlnjlkj nlkjlkjkljl okopokipoipo oipipipo i
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    public static class PKCS12PBE        extends JDKAlgorithmParameters    {        PKCS12PBEParams params;        protected byte[] engineGetEncoded()         {            try            {                return params.getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Oooops! " + e.toString());            }        }        protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format))            {                return engineGetEncoded();            }            return null;        }        protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == PBEParameterSpec.class)            {                return new PBEParameterSpec(params.getIV(),                                params.getIterations().intValue());            }            throw new InvalidParameterSpecException("unknown parameter spec passed to PKCS12 PBE parameters object.");        }        protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof PBEParameterSpec))            {                throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");            }            PBEParameterSpec    pbeSpec = (PBEParameterSpec)paramSpec;            this.params = new PKCS12PBEParams(pbeSpec.getSalt(),                                pbeSpec.getIterationCount());        }        protected void engineInit(            byte[] params)             throws IOException        {            this.params = PKCS12PBEParams.getInstance(ASN1Object.fromByteArray(params));        }        protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (isASN1FormatString(format))            {                engineInit(params);                return;            }            throw new IOException("Unknown parameters format in PKCS12 PBE parameters object");        }        protected String engineToString()         {            return "PKCS12 PBE Parameters";        }    }    public static class DH        extends JDKAlgorithmParameters    {        DHParameterSpec     currentSpec;        /**         * Return the PKCS#3 ASN.1 structure DHParameter.         * <p>         * <pre>         *  DHParameter ::= SEQUENCE {         *                   prime INTEGER, -- p         *                   base INTEGER, -- g         *                   privateValueLength INTEGER OPTIONAL}         * </pre>         */        protected byte[] engineGetEncoded()         {            DHParameter dhP = new DHParameter(currentSpec.getP(), currentSpec.getG(), currentSpec.getL());            try            {                return dhP.getEncoded(ASN1Encodable.DER);                            }            catch (IOException e)            {                throw new RuntimeException("Error encoding DHParameters");            }        }        protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format))            {                return engineGetEncoded();            }            return null;        }        protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == DHParameterSpec.class)            {                return currentSpec;            }            throw new InvalidParameterSpecException("unknown parameter spec passed to DH parameters object.");        }        protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof DHParameterSpec))            {                throw new InvalidParameterSpecException("DHParameterSpec required to initialise a Diffie-Hellman algorithm parameters object");            }            this.currentSpec = (DHParameterSpec)paramSpec;        }        protected void engineInit(            byte[] params)             throws IOException        {            try            {                DHParameter dhP = new DHParameter((ASN1Sequence)ASN1Object.fromByteArray(params));                if (dhP.getL() != null)                {                    currentSpec = new DHParameterSpec(dhP.getP(), dhP.getG(), dhP.getL().intValue());                }                else                {                    currentSpec = new DHParameterSpec(dhP.getP(), dhP.getG());                }            }            catch (ClassCastException e)            {                throw new IOException("Not a valid DH Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid DH Parameter encoding.");            }        }        protected void engineInit(            byte[] params,            String format)             throws IOException        {            if (isASN1FormatString(format))            {                engineInit(params);            }            else            {                throw new IOException("Unknown parameter format " + format);            }        }        protected String engineToString()         {            return "Diffie-Hellman Parameters";        }    }    public static class DSA        extends JDKAlgorithmParameters    {        DSAParameterSpec     currentSpec;        /**         * Return the X.509 ASN.1 structure DSAParameter.         * <p>         * <pre>         *  DSAParameter ::= SEQUENCE {         *                   prime INTEGER, -- p         *                   subprime INTEGER, -- q         *                   base INTEGER, -- g}         * </pre>         */        protected byte[] engineGetEncoded()         {            DSAParameter dsaP = new DSAParameter(currentSpec.getP(), currentSpec.getQ(), currentSpec.getG());            try            {                return dsaP.getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Error encoding DSAParameters");            }        }        protected byte[] engineGetEncoded(            String format)         {            if (isASN1FormatString(format))            {                return engineGetEncoded();            }            return null;        }        protected AlgorithmParameterSpec localEngineGetParameterSpec(            Class paramSpec)             throws InvalidParameterSpecException        {            if (paramSpec == DSAParameterSpec.class)            {                return currentSpec;            }            throw new InvalidParameterSpecException("unknown parameter spec passed to DSA parameters object.");        }        protected void engineInit(            AlgorithmParameterSpec paramSpec)             throws InvalidParameterSpecException        {            if (!(paramSpec instanceof DSAParameterSpec))            {                throw new InvalidParameterSpecException("DSAParameterSpec required to initialise a DSA algorithm parameters object");            }            this.currentSpec = (DSAParameterSpec)paramSpec;        }        protected void engineInit(            byte[] params)             throws IOException        {            try            {                DSAParameter dsaP = new DSAParameter((ASN1Sequence)ASN1Object.fromByteArray(params));                currentSpec = new DSAParameterSpec(dsaP.getP(), dsaP.getQ(), dsaP.getG());            }            catch (ClassCastException e)            {                throw new IOException("Not a valid DSA Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid DSA 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 "DSA Parameters";        }    }        public static class GOST3410        extends JDKAlgorithmParameters    {        GOST3410ParameterSpec     currentSpec;                /**         * Return the X.509 ASN.1 structure GOST3410Parameter.         * <p>         * <pre>         *  GOST3410Parameter ::= SEQUENCE {         *                   prime INTEGER, -- p         *                   subprime INTEGER, -- q         *                   base INTEGER, -- a}         * </pre>         */        protected byte[] engineGetEncoded()        {            GOST3410PublicKeyAlgParameters gost3410P = new GOST3410PublicKeyAlgParameters(new DERObjectIdentifier(currentSpec.getPublicKeyParamSetOID()), new DERObjectIdentifier(currentSpec.getDigestParamSetOID()), new DERObjectIdentifier(currentSpec.getEncryptionParamSetOID()));            try            {                return gost3410P.getEncoded(ASN1Encodable.DER);            }            catch (IOException e)            {                throw new RuntimeException("Error encoding GOST3410Parameters");            }        }                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 == GOST3410PublicKeyParameterSetSpec.class)            {                return currentSpec;            }                        throw new InvalidParameterSpecException("unknown parameter spec passed to GOST3410 parameters object.");        }                protected void engineInit(                AlgorithmParameterSpec paramSpec)        throws InvalidParameterSpecException        {            if (!(paramSpec instanceof GOST3410ParameterSpec))            {                throw new InvalidParameterSpecException("GOST3410ParameterSpec required to initialise a GOST3410 algorithm parameters object");            }                        this.currentSpec = (GOST3410ParameterSpec)paramSpec;        }                protected void engineInit(                byte[] params)        throws IOException        {            try            {                ASN1Sequence seq = (ASN1Sequence) ASN1Object.fromByteArray(params);                this.currentSpec = GOST3410ParameterSpec.fromPublicKeyAlg(                    new GOST3410PublicKeyAlgParameters(seq));            }            catch (ClassCastException e)            {                throw new IOException("Not a valid GOST3410 Parameter encoding.");            }            catch (ArrayIndexOutOfBoundsException e)            {                throw new IOException("Not a valid GOST3410 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 "GOST3410 Parameters";        }    }    public static class ElGamal        extends JDKAlgorithmParameters    {        ElGamalParameterSpec     currentSpec;        /**         * Return the X.509 ASN.1 structure ElGamalParameter.         * <p>         * <pre>         *  ElGamalParameter ::= SEQUENCE {         *                   prime INTEGER, -- p         *                   base INTEGER, -- g}         * </pre>         */        protected byte[] engineGetEncoded()         {            ElGamalParameter elP = new ElGamalParameter(currentSpec.getP(), currentSpec.getG());            try

⌨️ 快捷键说明

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