System.Security.Cryptography.RSACryptoServiceProvider.Decrypt C# (CSharp) Method

Decrypt() public method

public Decrypt ( byte data, RSAEncryptionPadding padding ) : byte[]
data byte
padding RSAEncryptionPadding
return byte[]
        public override byte[] Decrypt(byte[] data, RSAEncryptionPadding padding)
        {
            if (data == null)
                throw new ArgumentNullException(nameof(data));
            if (padding == null)
                throw new ArgumentNullException(nameof(padding));

            if (padding == RSAEncryptionPadding.Pkcs1)
            {
                return Decrypt(data, fOAEP: false);
            }
            else if (padding == RSAEncryptionPadding.OaepSHA1)
            {
                return Decrypt(data, fOAEP: true);
            }
            else
            {
                throw PaddingModeNotSupported();
            }
        }

Same methods

RSACryptoServiceProvider::Decrypt ( byte rgb, bool fOAEP ) : byte[]

Usage Example

        public RecordType AddRecord(string OName, string OPoint)
        {
            byte[] Name = Convert.FromBase64String(OName);
            byte[] Point = Convert.FromBase64String(OPoint);
            StreamReader sr = new StreamReader(Server.MapPath("App_Data\rightcolor_private.xml"));
            string ALL = sr.ReadToEnd();
            sr.Close();

            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(2048);
            RSA.FromXmlString(ALL);

            string RealName = System.Text.Encoding.UTF8.GetString(RSA.Decrypt(Name, false));
            long RealPoint = long.Parse(System.Text.Encoding.UTF8.GetString(RSA.Decrypt(Point, false)));

            RecordType AllowInsert = RecordType.None;
            long ForeverMax = (from inc in Data.Records orderby inc.Point descending select inc.Point).Skip(9).Take(1).SingleOrDefault();
            if (RealPoint > ForeverMax)
            {
                AllowInsert = RecordType.Forever;
                goto Insert;
            }
            long MonthMax = (from inc in Data.Records where inc.AddDate > DateTime.Now.AddMonths(-1) orderby inc.Point descending select inc.Point).Skip(9).Take(1).SingleOrDefault();
            if (RealPoint > MonthMax)
            {
                AllowInsert = RecordType.Month;
                goto Insert;
            }
            long WeekMax = (from inc in Data.Records where inc.AddDate > DateTime.Now.AddDays(-7) orderby inc.Point descending select inc.Point).Skip(9).Take(1).SingleOrDefault();
            if (RealPoint > WeekMax)
            {
                AllowInsert = RecordType.Week;
                goto Insert;
            }
            long DayMax = (from inc in Data.Records where inc.AddDate > DateTime.Now.AddDays(-1) orderby inc.Point descending select inc.Point).Skip(9).Take(1).SingleOrDefault();
            if (RealPoint > DayMax)
            {
                AllowInsert = RecordType.Day;
            }
            Insert:
            if (AllowInsert != RecordType.None)
            {
                Record NewRecord = new Record();
                NewRecord.Person = RealName;
                NewRecord.Point = RealPoint;
                NewRecord.AddDate = DateTime.Now;
                Data.Records.InsertOnSubmit(NewRecord);
                Data.SubmitChanges();
            }
            return AllowInsert;
        }
All Usage Examples Of System.Security.Cryptography.RSACryptoServiceProvider::Decrypt