Ejemplo n.º 1
0
        //*************************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="plainData"></param>
        /// <param name="fOAEP"></param>
        /// <param name="certificate"></param>
        /// <returns></returns>
        ///
        //*************************************************************************

        public byte[] Encrypt(byte[] plainData, bool fOAEP,
                              X509Certificate2 certificate)
        {
            try
            {
                return(X509Krypto.EncryptImpl(plainData, fOAEP, certificate));
            }
            catch (Exception ex)
            {
                throw new Exception("Exception in Encrypt() : " +
                                    UnwindExceptionMessages(ex));
            }
        }
Ejemplo n.º 2
0
        //*************************************************************************
        ///
        /// <summary>
        ///
        /// </summary>
        /// <param name="storeName"></param>
        /// <param name="storeLocation"></param>
        /// <param name="thumbprint"></param>
        /// <returns></returns>
        ///
        //*************************************************************************

        public X509Certificate2 FetchCertFromStore(StoreName storeName, StoreLocation
                                                   storeLocation, string thumbprint)
        {
            try
            {
                return(X509Krypto.FetchCertFromStoreImpl(storeName, storeLocation, thumbprint));
            }
            catch (Exception ex)
            {
                throw new Exception("Exception in FetchCertFromStore() : " +
                                    UnwindExceptionMessages(ex));
            }
        }
Ejemplo n.º 3
0
        public static byte[] EncryptImpl(byte[] plainData, bool fOAEP, X509Certificate2 certificate)
        {
            if (plainData == null)
            {
                throw new ArgumentNullException("plainData");
            }

            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }

            using (var provider = new RSACryptoServiceProvider())
            {
                provider.FromXmlString(X509Krypto.GetPublicKey(certificate));
                return(provider.Encrypt(plainData, fOAEP));
            }
        }