Exemplo n.º 1
0
        public byte[] DecryptDataWithRsaFile(string rsaPrivateParamsFilePath, string fileKey, byte[] encryptData)
        {
            if (!File.Exists(rsaPrivateParamsFilePath))
            {
                return(null);
            }
            RsaParametersSerializable rsaParameters;

            Key = fileKey;
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                DecrypFile(rsaPrivateParamsFilePath, fileKey);
                using (FileStream fs = new FileStream(rsaPrivateParamsFilePath, FileMode.Open))
                {
                    rsaParameters = (RsaParametersSerializable)formatter.Deserialize(fs);
                }
                EncryptFile(rsaPrivateParamsFilePath, fileKey);
            }
            catch (Exception)
            {
                return(null);
            }
            return(RsaCypher.RsaDecrypt(encryptData, rsaParameters.RsaParameters, false));
        }
Exemplo n.º 2
0
        public byte[] EncryptDataWithRsaFile(string rsaPublicParamsFilePath, byte[] encryptData)
        {
            if (!File.Exists(rsaPublicParamsFilePath))
            {
                return(null);
            }
            RSAParameters   rsaParameters;
            BinaryFormatter formatter = new BinaryFormatter();

            try
            {
                using (FileStream fs = new FileStream(rsaPublicParamsFilePath, FileMode.Open))
                {
                    rsaParameters = (RSAParameters)formatter.Deserialize(fs);
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(RsaCypher.RsaEncrypt(encryptData, rsaParameters, false));
        }