Пример #1
0
        /// <summary>
        /// Resolve the Key object.
        ///
        /// <para> This method supports three Type/format combinations:
        /// <ul>
        /// <li> Type.SECRET/"RAW" - returns a SecretKeySpec object
        /// constructed using encoded key bytes and algorithm
        /// <li> Type.PUBLIC/"X.509" - gets a KeyFactory instance for
        /// the key algorithm, constructs an X509EncodedKeySpec with the
        /// encoded key bytes, and generates a public key from the spec
        /// <li> Type.PRIVATE/"PKCS#8" - gets a KeyFactory instance for
        /// the key algorithm, constructs a PKCS8EncodedKeySpec with the
        /// encoded key bytes, and generates a private key from the spec
        /// </ul>
        ///
        /// </para>
        /// <para>
        ///
        /// </para>
        /// </summary>
        /// <returns> the resolved Key object
        /// </returns>
        /// <exception cref="ObjectStreamException"> if the Type/format
        ///  combination is unrecognized, if the algorithm, key format, or
        ///  encoded key bytes are unrecognized/invalid, of if the
        ///  resolution of the key fails for any reason </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected Object readResolve() throws ObjectStreamException
        protected internal virtual Object ReadResolve()
        {
            try
            {
                if (Type == Type.SECRET && RAW.Equals(Format))
                {
                    return(new SecretKeySpec(Encoded, Algorithm));
                }
                else if (Type == Type.PUBLIC && X509.Equals(Format))
                {
                    KeyFactory f = KeyFactory.GetInstance(Algorithm);
                    return(f.GeneratePublic(new X509EncodedKeySpec(Encoded)));
                }
                else if (Type == Type.PRIVATE && PKCS8.Equals(Format))
                {
                    KeyFactory f = KeyFactory.GetInstance(Algorithm);
                    return(f.GeneratePrivate(new PKCS8EncodedKeySpec(Encoded)));
                }
                else
                {
                    throw new NotSerializableException("unrecognized type/format combination: " + Type + "/" + Format);
                }
            }
            catch (NotSerializableException nse)
            {
                throw nse;
            }
            catch (Exception e)
            {
                NotSerializableException nse = new NotSerializableException("java.security.Key: " + "[" + Type + "] " + "[" + Algorithm + "] " + "[" + Format + "]");
                nse.InitCause(e);
                throw nse;
            }
        }
Пример #2
0
        /// <summary>
        /// Replaces the {@code CertPath} to be serialized with a
        /// {@code CertPathRep} object.
        /// </summary>
        /// <returns> the {@code CertPathRep} to be serialized
        /// </returns>
        /// <exception cref="ObjectStreamException"> if a {@code CertPathRep} object
        /// representing this certification path could not be created </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected Object writeReplace() throws java.io.ObjectStreamException
        protected internal virtual Object WriteReplace()
        {
            try
            {
                return(new CertPathRep(Type_Renamed, Encoded));
            }
            catch (CertificateException ce)
            {
                NotSerializableException nse = new NotSerializableException("java.security.cert.CertPath: " + Type_Renamed);
                nse.InitCause(ce);
                throw nse;
            }
        }
Пример #3
0
            /// <summary>
            /// Returns a {@code CertPath} constructed from the type and data.
            /// </summary>
            /// <returns> the resolved {@code CertPath} object
            /// </returns>
            /// <exception cref="ObjectStreamException"> if a {@code CertPath} could not
            /// be constructed </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected Object readResolve() throws java.io.ObjectStreamException
            protected internal virtual Object ReadResolve()
            {
                try
                {
                    CertificateFactory cf = CertificateFactory.GetInstance(Type);
                    return(cf.GenerateCertPath(new ByteArrayInputStream(Data)));
                }
                catch (CertificateException ce)
                {
                    NotSerializableException nse = new NotSerializableException("java.security.cert.CertPath: " + Type);
                    nse.InitCause(ce);
                    throw nse;
                }
            }