Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1022491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:28:27+00:00 2026-05-16T11:28:27+00:00

I would like to embed some C# .Net code that does some simple Encryption/Decryption

  • 0

I would like to embed some C# .Net code that does some simple Encryption/Decryption functions into a web page. This will be an internal web page so users will be implicitly trusted. Is there any way to do this? I will need to hit user’s Windows-MY key store (via CAPI) to pull out the keys for decryption and hit an LDAP server to grab public keys for encryption.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:28:27+00:00Added an answer on May 16, 2026 at 11:28 am

    I ended up faking a COM object using C# then using JavaScript to call that COM object and was able to interact with the CAPI through the browser that way.

    JavaScript:

    <html>
    <head>
    <script language="javascript">
    var keystore = new ActiveXObject("RBCrypto.KeyStore");
    
    function getCertList()
    {
       try {
         keystore.openKeyStore("MY", true, false);
         var size = keystore.getStoreSize();
    
         var list = document.getElementById('list');
         list.size = size;
    
         for(var i = 0; i < size; i++)
         {
            var fname = keystore.getFriendlyName(i, true);
            var opt = new Option(fname, fname);
            list.options.add(opt);
         }
       }
       catch(err)
       {
         alert(err.description);
       }
    }
    </script>
    </head>
    <body onload="getCertList()">
       <center>
        <h2>KeyStore Test</h2>
        <hr />
        <br />
        <select id="list"></select>
       </center>
    </body>
    </html>
    

    C#:

    using System;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Cryptography;
    using System.Security.Cryptography.X509Certificates;
    
    namespace RBCrypto
    {
        public interface AXInterface
        {
            void openKeyStore(string storeName, bool currentUser, bool readOnly);
            int getStoreSize();
            string getFriendlyName(int index, bool subjectNameIfEmpty);
        }
    
        [ClassInterface(ClassInterfaceType.AutoDual)]
        public class KeyStore :AXInterface
        {
            public void openKeyStore(string storeName, bool currentUser, bool readOnly)
            {
                if (keystoreInitialized)
                    throw new Exception("Key Store must be closed before re-initialization");
    
                try
                {
                    if (currentUser) //user wants to open store used by the current user
                        certificateStore = new X509Store(storeName, StoreLocation.CurrentUser);
                    else             //user wants to open store used by local machine
                        certificateStore = new X509Store(storeName, StoreLocation.LocalMachine);
    
                    if (readOnly)
                        certificateStore.Open(OpenFlags.ReadOnly);
                    else
                        certificateStore.Open(OpenFlags.ReadWrite);
    
                    allCertificates = certificateStore.Certificates;
    
                    if (allCertificates == null)
                    {
                        certificateStore.Close();
                        throw new NullReferenceException("Certificates could not be gathered");
                    }
    
                    keystoreInitialized = true;
                }
                catch (ArgumentException ae)
                {
                    throw ae;
                }
                catch (SecurityException se)
                {
                    throw se;
                }
                catch (CryptographicException ce)
                {
                    throw ce;
                }
                catch (NullReferenceException ne)
                {
                    throw ne;
                }
            }
    
            ....
       }
    }
    

    C# AssemblyInfo:

    // Setting ComVisible to false makes the types in this assembly not visible 
    // to COM components.  If you need to access a type in this assembly from 
    // COM, set the ComVisible attribute to true on that type.
    [assembly: ComVisible(true)]
    

    In order for this to work the user has to isntall your .dll on their machine (Make sure you specify to register your .dll as vsdraCOM in your installer) and they have to add your site to their trusted sites.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We would like to embed some code in each ASP.NET page that queries its
I would like to embed Clojure code into Java. This site was helpful in
I would like to embed some SVG in an HTML page in a way
I want to embed some HTML on my website... I would like that: SEO
I would like to embed a javascript engine into an ANSI C application. In
I have a custom View that I would like to embed in an WebView.
Hey guys, I have developed a small site that i would like to embed
I have a ViewController that has its own NIB. I would like to embed
I would like to run this script (embed drive list in a site) that
I would like to embed some Lua script in my C application.....specifically for LOGGING.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.