Click here to Skip to main content
14,325,629 members
   

C#

 
GeneralRe: How to terminate a login session if disconnected from internet Pin
fukchai200031-May-07 21:42
memberfukchai200031-May-07 21:42 
GeneralRe: How to terminate a login session if disconnected from internet Pin
Dave Kreskowiak1-Jun-07 4:25
mveDave Kreskowiak1-Jun-07 4:25 
QuestionXML over serial port Pin
sklepikov31-May-07 13:40
membersklepikov31-May-07 13:40 
AnswerRe: XML over serial port Pin
Christian Graus31-May-07 13:57
protectorChristian Graus31-May-07 13:57 
GeneralRe: XML over serial port Pin
sklepikov1-Jun-07 3:44
membersklepikov1-Jun-07 3:44 
QuestionGive Access to Certificate in Store Pin
mikker_12331-May-07 13:02
membermikker_12331-May-07 13:02 
AnswerRe: Give Access to Certificate in Store Pin
blackjack215031-May-07 23:55
memberblackjack215031-May-07 23:55 
GeneralRe: Give Access to Certificate in Store PinPopular
mikker_1231-Jun-07 0:23
membermikker_1231-Jun-07 0: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 13:49
memberDotNet_Naeem2-Sep-09 13:49 
GeneralRe: Give Access to Certificate in Store Pin
SHUBHAM SHARMA6-May-18 19:51
memberSHUBHAM SHARMA6-May-18 19:51 
Questionhow to access protected-pass folder Pin
alex.almeida31-May-07 12:26
memberalex.almeida31-May-07 12:26 
AnswerRe: how to access protected-pass folder Pin
mikker_12331-May-07 13:12
membermikker_12331-May-07 13:12 
GeneralRe: how to access protected-pass folder Pin
alex.almeida1-Jun-07 2:28
memberalex.almeida1-Jun-07 2:28 
AnswerRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 13:29
mveDave Kreskowiak31-May-07 13:29 
GeneralRe: how to access protected-pass folder Pin
Christian Graus31-May-07 13:30
protectorChristian Graus31-May-07 13:30 
GeneralRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 13:43
mveDave Kreskowiak31-May-07 13:43 
GeneralRe: how to access protected-pass folder Pin
mikker_12331-May-07 13:48
membermikker_12331-May-07 13:48 
GeneralRe: how to access protected-pass folder Pin
Dave Kreskowiak31-May-07 17:25
mveDave Kreskowiak31-May-07 17:25 
GeneralRe: how to access protected-pass folder Pin
alex.almeida1-Jun-07 3:48
memberalex.almeida1-Jun-07 3:48 
GeneralRe: how to access protected-pass folder Pin
mikker_1231-Jun-07 7:59
membermikker_1231-Jun-07 7:59 
GeneralRe: how to access protected-pass folder Pin
alex.almeida4-Jun-07 4:01
memberalex.almeida4-Jun-07 4:01 
QuestionHow to monitor an incoming TCP/IP connection in C#? Pin
adeeeljan31-May-07 11:14
memberadeeeljan31-May-07 11:14 
AnswerRe: How to monitor an incoming TCP/IP connection in C#? Pin
Dave Kreskowiak31-May-07 13:21
mveDave Kreskowiak31-May-07 13:21 
QuestionForm Opacity and OnClose() Pin
Wraith Lunati31-May-07 11:01
memberWraith Lunati31-May-07 11:01 
AnswerRe: Form Opacity and OnClose() Pin
Christian Graus31-May-07 11:10
protectorChristian Graus31-May-07 11: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.