Exemplo n.º 1
0
        /// <summary>
        /// Verifies the signature.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <param name="dataHash">The data hash.</param>
        /// <param name="hashSize">Size of the hash.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="signatureSize">Size of the signature.</param>
        /// <returns></returns>
        public static bool VerifySignature(byte[] certificate, byte[] dataHash, int hashSize, byte[] signature, int signatureSize)
        {
            EIDCertificate cert = new EIDCertificate();

            cert.certificateLength = certificate.Length;
            Array.Copy(certificate, cert.certificate, Math.Min(certificate.Length, EIDDataLength.EidMaxCertLen));
            return(NativeMethods.VerifySignature(cert, dataHash, hashSize, signature, signatureSize));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Displays the certificate.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 public void DisplayCertificate(string fileName)
 {
     if (reader != null)
     {
         EIDCertificate cert = new EIDCertificate();
         NativeMethods.LoadCertificate(fileName, cert);
         NativeMethods.DisplayCertificate(cert);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Reads the certificate.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <returns></returns>
        public byte[] ReadCertificate(CertificateType certificate)
        {
            if (reader != null)
            {
                NativeMethods.SelectReader(reader.Index);
            }

            bool           result = false;
            EIDCertificate cert   = new EIDCertificate();

            switch (certificate)
            {
            case CertificateType.CaCertificate:
                result = NativeMethods.ReadCaCertificate(cert);
                break;

            case CertificateType.RootCaCertificate:
                result = NativeMethods.ReadRootCaCertificate(cert);
                break;

            case CertificateType.RrnCertificate:
                result = NativeMethods.ReadRrnCertificate(cert);
                break;

            case CertificateType.AuthenticationCertificate:
                result = NativeMethods.ReadAuthenticationCertificate(cert);
                break;

            case CertificateType.NonRepudiationCertificate:
                result = NativeMethods.ReadNonRepudiationCertificate(cert);
                break;

            default:
                break;
            }

            if (result)
            {
                if (cert.certificateLength == 0)
                {
                    return(null);
                }

                byte[] buffer = new byte[cert.certificateLength];
                Array.Copy(cert.certificate, buffer, cert.certificateLength);
                return(buffer);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Displays the certificate.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        public void DisplayCertificate(CertificateType certificate)
        {
            if (reader != null)
            {
                NativeMethods.SelectReader(reader.Index);
            }

            bool           result = false;
            EIDCertificate cert   = new EIDCertificate();

            switch (certificate)
            {
            case CertificateType.CaCertificate:
                result = NativeMethods.ReadCaCertificate(cert);
                break;

            case CertificateType.RootCaCertificate:
                result = NativeMethods.ReadRootCaCertificate(cert);
                break;

            case CertificateType.RrnCertificate:
                result = NativeMethods.ReadRrnCertificate(cert);
                break;

            case CertificateType.AuthenticationCertificate:
                result = NativeMethods.ReadAuthenticationCertificate(cert);
                break;

            case CertificateType.NonRepudiationCertificate:
                result = NativeMethods.ReadNonRepudiationCertificate(cert);
                break;

            default:
                break;
            }

            if (result)
            {
                NativeMethods.DisplayCertificate(cert);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Encodes the certificate.
        /// </summary>
        /// <param name="certificate">The certificate.</param>
        /// <returns></returns>
        public byte[] EncodeCertificate(CertificateType certificate)
        {
            if (reader != null)
            {
                NativeMethods.SelectReader(reader.Index);
            }

            bool           result = false;
            EIDCertificate cert   = new EIDCertificate();

            switch (certificate)
            {
            case CertificateType.CaCertificate:
                result = NativeMethods.ReadCaCertificate(cert);
                break;

            case CertificateType.RootCaCertificate:
                result = NativeMethods.ReadRootCaCertificate(cert);
                break;

            case CertificateType.RrnCertificate:
                result = NativeMethods.ReadRrnCertificate(cert);
                break;

            case CertificateType.AuthenticationCertificate:
                result = NativeMethods.ReadAuthenticationCertificate(cert);
                break;

            case CertificateType.NonRepudiationCertificate:
                result = NativeMethods.ReadNonRepudiationCertificate(cert);
                break;

            default:
                break;
            }

            if (result)
            {
                if (cert.certificateLength == 0)
                {
                    return(null);
                }

                int    len        = NativeMethods.GetEncodedCertificateSize(cert);
                byte[] buffer     = new byte[len];
                int    encodedLen = NativeMethods.EncodeCertificate(cert, buffer, len);

                if (encodedLen > len)
                {
                    return(null);
                }

                if (encodedLen == len)
                {
                    return(buffer);
                }

                byte[] encodedCert = new byte[encodedLen];
                Array.Copy(buffer, encodedCert, encodedLen);
                return(encodedCert);
            }
            else
            {
                return(null);
            }
        }