Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: The form appeared in debug mode even though I deleted it. Pin
OriginalGriff26-Jan-15 3:55
mveOriginalGriff26-Jan-15 3:55 
QuestionCustom properties OpenXml C# Pin
Member 1139687825-Jan-15 19:57
Member 1139687825-Jan-15 19:57 
AnswerRe: Custom properties OpenXml C# Pin
Richard Deeming26-Jan-15 2:19
mveRichard Deeming26-Jan-15 2:19 
Questioncrystal report problem Pin
shuaibwasifkhan25-Jan-15 10:31
shuaibwasifkhan25-Jan-15 10:31 
AnswerRe: crystal report problem Pin
Mycroft Holmes25-Jan-15 21:54
professionalMycroft Holmes25-Jan-15 21:54 
GeneralRe: crystal report problem Pin
BhavinPandya27-Jan-15 21:47
BhavinPandya27-Jan-15 21:47 
GeneralRe: crystal report problem Pin
Mycroft Holmes27-Jan-15 21:57
professionalMycroft Holmes27-Jan-15 21:57 
QuestionCross-platform Encryption / Decryption Pin
Jassim Rahma24-Jan-15 22:59
Jassim Rahma24-Jan-15 22:59 
Hi,

I have .NET WinForm application in C# and I will make Web application for it using PHP.

I would like to ask what's the best way to encrypt / decrypt user authentication so it wll work on both WinForm and PHP portal?

I am currently using this in C#:

C#
user_password = cipher_utility.Encrypt<RijndaelManaged>(result, "xxxx", "xxxxxxxxx");




C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace Application_Class_Library
{
    public class cipher_utility
    {
        public static string Encrypt<T>(string value, string password, string salt) where T : SymmetricAlgorithm, new()
        {
            DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));

            SymmetricAlgorithm algorithm = new T();

            byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
            byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);

            ICryptoTransform transform = algorithm.CreateEncryptor(rgbKey, rgbIV);

            using (MemoryStream buffer = new MemoryStream())
            {
                using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Write))
                {
                    using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode))
                    {
                        writer.Write(value);
                    }
                }

                return Convert.ToBase64String(buffer.ToArray());
            }
        }

        public static string Decrypt<T>(string text, string password, string salt) where T : SymmetricAlgorithm, new()
        {
            DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));

            SymmetricAlgorithm algorithm = new T();

            byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
            byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);

            ICryptoTransform transform = algorithm.CreateDecryptor(rgbKey, rgbIV);

            using (MemoryStream buffer = new MemoryStream(Convert.FromBase64String(text)))
            {
                using (CryptoStream stream = new CryptoStream(buffer, transform, CryptoStreamMode.Read))
                {
                    using (StreamReader reader = new StreamReader(stream, Encoding.Unicode))
                    {
                        return reader.ReadToEnd();
                    }
                }
            }
        }
    }
}



Technology News @ www.JassimRahma.com

AnswerRe: Cross-platform Encryption / Decryption Pin
Richard MacCutchan25-Jan-15 1:10
mveRichard MacCutchan25-Jan-15 1:10 
QuestionWhy doesn't my code find the .SelectedIndex? Pin
rfresh24-Jan-15 12:32
rfresh24-Jan-15 12:32 
AnswerRe: Why doesn't my code find the .SelectedIndex? Pin
BillWoodruff24-Jan-15 18:27
professionalBillWoodruff24-Jan-15 18:27 
AnswerRe: Why doesn't my code find the .SelectedIndex? Pin
OriginalGriff24-Jan-15 21:53
mveOriginalGriff24-Jan-15 21:53 
GeneralRe: Why doesn't my code find the .SelectedIndex? Pin
rfresh25-Jan-15 5:05
rfresh25-Jan-15 5:05 
GeneralRe: Why doesn't my code find the .SelectedIndex? Pin
OriginalGriff25-Jan-15 5:20
mveOriginalGriff25-Jan-15 5:20 
Questionhow to add a image to header of exportinf pdf in devexpress gridview Pin
Member 1064949524-Jan-15 11:04
Member 1064949524-Jan-15 11:04 
QuestionEncoding.ASCII.GetString(byte[]) and CR LF Pin
TMattC24-Jan-15 10:42
TMattC24-Jan-15 10:42 
AnswerRe: Encoding.ASCII.GetString(byte[]) and CR LF Pin
Richard Andrew x6424-Jan-15 16:32
professionalRichard Andrew x6424-Jan-15 16:32 
GeneralRe: Encoding.ASCII.GetString(byte[]) and CR LF Pin
TMattC25-Jan-15 1:32
TMattC25-Jan-15 1:32 
Questionmemory leak calling C functions in C# Pin
jpvi24-Jan-15 2:23
jpvi24-Jan-15 2:23 
AnswerRe: memory leak calling C functions in C# Pin
Dave Kreskowiak24-Jan-15 4:26
mveDave Kreskowiak24-Jan-15 4:26 
GeneralRe: memory leak calling C functions in C# Pin
jpvi24-Jan-15 5:11
jpvi24-Jan-15 5:11 
QuestionMvc Fileupload control Pin
Member 1133082524-Jan-15 2:23
Member 1133082524-Jan-15 2:23 
QuestionHow to change background color of a cell in Devexpress Grid when i click select them ? Pin
Member 245846723-Jan-15 22:14
Member 245846723-Jan-15 22:14 
QuestionDifference between Array and Loop. Pin
Member 1116162523-Jan-15 18:44
Member 1116162523-Jan-15 18:44 
AnswerRe: Difference between Array and Loop. Pin
Peter Leow23-Jan-15 18:58
professionalPeter Leow23-Jan-15 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.