Click here to Skip to main content
15,122,149 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to terminate a login session if disconnected from internet Pin
fukchai200031-May-07 22:42
Memberfukchai200031-May-07 22:42 
GeneralRe: How to terminate a login session if disconnected from internet Pin
Dave Kreskowiak1-Jun-07 5:25
mveDave Kreskowiak1-Jun-07 5:25 
QuestionXML over serial port Pin
sklepikov31-May-07 14:40
Membersklepikov31-May-07 14:40 
AnswerRe: XML over serial port Pin
Christian Graus31-May-07 14:57
protectorChristian Graus31-May-07 14:57 
GeneralRe: XML over serial port Pin
sklepikov1-Jun-07 4:44
Membersklepikov1-Jun-07 4:44 
QuestionGive Access to Certificate in Store Pin
mikker_12331-May-07 14:02
Membermikker_12331-May-07 14:02 
AnswerRe: Give Access to Certificate in Store Pin
blackjack21501-Jun-07 0:55
Memberblackjack21501-Jun-07 0:55 
GeneralRe: Give Access to Certificate in Store PinPopular
mikker_1231-Jun-07 1:23
Membermikker_1231-Jun-07 1:23 
Dunno... Add method works great for me. Anyways I found some kind of solution googling, it works, but I don't like it. Anyways, if someone has better solution please post, until then I'll use this:

private static void PlaceInStore(X509Certificate2 cert)
{
    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

    try
    {
        store.Open(OpenFlags.ReadWrite);

        if (!store.Certificates.Contains(cert))
            store.Add(cert);

        int indexInStore = store.Certificates.IndexOf(cert);
        cert = store.Certificates[indexInStore];

        AddAccessToCertificate(cert, "ARCHITECT\\testuser");
    }
    finally
    {
        store.Close();
    }
}

private static void AddAccessToCertificate(X509Certificate2 cert, string user)
{
    RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;

    if (rsa != null)
    {
        string keyfilepath =
            FindKeyLocation(rsa.CspKeyContainerInfo.UniqueKeyContainerName);

        FileInfo file = new FileInfo(keyfilepath + "\\" +
            rsa.CspKeyContainerInfo.UniqueKeyContainerName);

        FileSecurity fs = file.GetAccessControl();

        NTAccount account = new NTAccount(user);
        fs.AddAccessRule(new FileSystemAccessRule(account,
        FileSystemRights.FullControl, AccessControlType.Allow));

        file.SetAccessControl(fs);
    }
}

private static string FindKeyLocation(string keyFileName)
{
    string text1 =
    Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
    string text2 = text1 + @"\Microsoft\Crypto\RSA\MachineKeys";
    string[] textArray1 = Directory.GetFiles(text2, keyFileName);
    if (textArray1.Length > 0)
    {
        return text2;
    }
    string text3 =
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
    string text4 = text3 + @"\Microsoft\Crypto\RSA\";
    textArray1 = Directory.GetDirectories(text4);
    if (textArray1.Length > 0)
    {
        foreach (string text5 in textArray1)
        {
            textArray1 = Directory.GetFiles(text5, keyFileName);
            if (textArray1.Length != 0)
            {
                return text5;
            }
        }
    }
    return "Private key exists but is not accessible";
}

GeneralRe: Give Access to Certificate in Store Pin
DotNet_Naeem2-Sep-09 14:49
MemberDotNet_Naeem2-Sep-09 14:49 
GeneralRe: Give Access to Certificate in Store Pin
SHUBHAM SHARMA6-May-18 20:51
MemberSHUBHAM SHARMA6-May-18 20:51 
Questionhow to access protected-pass folder Pin
alex.almeida31-May-07 13:26
Memberalex.almeida31-May-07 13:26 
AnswerRe: how to access protected-pass folder Pin
mikker_12331-May-07 14:12
Membermikker_12331-May-07 14:12 
GeneralRe: how to access protected-pass folder Pin
alex.almeida1-Jun-07 3:28
Memberalex.almeida1-Jun-07 3:28 
AnswerRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 14:29
mveDave Kreskowiak31-May-07 14:29 
GeneralRe: how to access protected-pass folder Pin
Christian Graus31-May-07 14:30
protectorChristian Graus31-May-07 14:30 
GeneralRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 14:43
mveDave Kreskowiak31-May-07 14:43 
GeneralRe: how to access protected-pass folder Pin
mikker_12331-May-07 14:48
Membermikker_12331-May-07 14:48 
GeneralRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 18:25
mveDave Kreskowiak31-May-07 18:25 
GeneralRe: how to access protected-pass folder Pin
alex.almeida1-Jun-07 4:48
Memberalex.almeida1-Jun-07 4:48 
GeneralRe: how to access protected-pass folder Pin
mikker_1231-Jun-07 8:59
Membermikker_1231-Jun-07 8:59 
GeneralRe: how to access protected-pass folder Pin
alex.almeida4-Jun-07 5:01
Memberalex.almeida4-Jun-07 5:01 
QuestionHow to monitor an incoming TCP/IP connection in C#? Pin
adeeeljan31-May-07 12:14
Memberadeeeljan31-May-07 12:14 
AnswerRe: How to monitor an incoming TCP/IP connection in C#? Pin
Dave Kreskowiak31-May-07 14:21
mveDave Kreskowiak31-May-07 14:21 
QuestionForm Opacity and OnClose() Pin
Wraith Lunati31-May-07 12:01
MemberWraith Lunati31-May-07 12:01 
AnswerRe: Form Opacity and OnClose() Pin
Christian Graus31-May-07 12:10
protectorChristian Graus31-May-07 12:10 

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.