Click here to Skip to main content
15,891,529 members
Articles / Security

Encrypting Communication between C# and PHP

Rate me:
Please Sign up or sign in to vote.
4.91/5 (34 votes)
11 Oct 2011GPL344 min read 201.4K   4.4K   65  
Set up encrypted secure communication between C# and PHP using the AES and RSA algorithms.
<?xml version="1.0"?>
<doc>
    <assembly>
        <name>CS2PHPCryptography</name>
    </assembly>
    <members>
        <member name="M:CS2PHPCryptography.AEStoPHPCryptography.GenerateRandomKeys">
            <summary>
            Generate the cryptographically secure random 256 bit Key and 128 bit IV for the AES algorithm.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.AEStoPHPCryptography.Encrypt(System.String)">
            <summary>
            Encrypt a message and get the encrypted message in a URL safe form of base64.
            </summary>
            <param name="plainText">The message to encrypt.</param>
        </member>
        <member name="M:CS2PHPCryptography.AEStoPHPCryptography.Encrypt2(System.String)">
            <summary>
            Encrypt a message using AES.
            </summary>
            <param name="plainText">The message to encrypt.</param>
        </member>
        <member name="M:CS2PHPCryptography.AEStoPHPCryptography.Decrypt(System.String)">
            <summary>
            Decrypt a message that is in a url safe base64 encoded string.
            </summary>
            <param name="cipherText">The string to decrypt.</param>
        </member>
        <member name="M:CS2PHPCryptography.AEStoPHPCryptography.Decrypt2(System.Byte[])">
            <summary>
            Decrypt a message that was AES encrypted.
            </summary>
            <param name="cipherText">The string to decrypt.</param>
        </member>
        <member name="P:CS2PHPCryptography.AEStoPHPCryptography.EncryptionKeyString">
            <summary>
            Gets the encryption key as a base64 encoded string.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.AEStoPHPCryptography.EncryptionIVString">
            <summary>
            Gets the initialization key as a base64 encoded string.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.AEStoPHPCryptography.EncryptionKey">
            <summary>
            Gets the encryption key.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.AEStoPHPCryptography.EncryptionIV">
            <summary>
            Gets the initialization key.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.#ctor(System.String)">
            <summary>
            Create a new PHP compatible RSA encryptor from a certificate.
            </summary>
            <param name="certificateLocation">The file to load as a certificate.</param>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.#ctor">
            <summary>
            Create a new PHP compatible RSA encryptor. Make sure you load a certificate before trying to encrypt.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.LoadCertificateFromFile(System.String)">
            <summary>
            Create a new PHP compatible RSA encryptor from a certificate file.
            </summary>
            <param name="certificateLocation">The file to load as a certificate.</param>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.LoadCertificateFromString(System.String)">
            <summary>
            Create a new PHP compatible RSA encryptor from a certificate string.
            </summary>
            <param name="certificateText">The base64 encoded text to load as a certificate.</param>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.GetCertificate(System.String)">
            <summary>
            Load a public RSA key from a certificate string.
            </summary>
            <param name="key">The certificate text.</param>
            <exception cref="T:System.FormatException"></exception>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.GetCertificateFromFile(System.String)">
            <summary>
            Load a public RSA key from a certificate file.
            </summary>
            <param name="file">The certificate file.</param>
            <returns></returns>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.Encrypt(System.Byte[])">
            <summary>
            Encrypt a messages using the supplied public certificate.
            </summary>
            <param name="message">The message to encrypt.</param>
        </member>
        <member name="M:CS2PHPCryptography.RSAtoPHPCryptography.Encrypt(System.String)">
            <summary>
            Encrypt a messages using the supplied public certificate and returns the ciphertext as a base64 encoded string.
            </summary>
            <param name="message">The message to encrypt.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Get(System.String,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a GET request to a web page asynchronously. The result will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to GET.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Get(System.String)">
            <summary>
            Send a GET request to a web page asynchronously. The result will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to GET.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Post(System.String,CS2PHPCryptography.PostPackageBuilder,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a POST request to a web page asynchronously. The response will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="postVars">The list of variables to POST to the server.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Post(System.String,CS2PHPCryptography.PostPackageBuilder)">
            <summary>
            Send a POST request to a web page asynchronously. The response will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="postVars">The list of variables to POST to the server.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Post(System.String,System.String)">
            <summary>
            Send a POST request to a web page asynchronously. The response will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="data">The data to POST.</param>
        </member>
        <member name="M:CS2PHPCryptography.AsyncHttpControl.Post(System.String,System.String,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a POST request to a web page asynchronously. The response will be returned in OnHttpResponse.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="data">The data to POST.</param>
        </member>
        <member name="P:CS2PHPCryptography.AsyncHttpControl.IsBusy">
            <summary>
            Whether this object is currently in the process of fetching a request;
            </summary>
        </member>
        <member name="E:CS2PHPCryptography.AsyncHttpControl.OnHttpResponse">
            <summary>
            Raised when a response from the last HTTP request has arrived.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.OnHttpResponseEventArgs.ResponseBody">
            <summary>
            The body of the response
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.OnHttpResponseEventArgs.Error">
            <summary>
            Whether or not there was an error. If there was, then the error will be in the ResponseBody.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Get(System.String,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a GET request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to GET.</param>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Get(System.String)">
            <summary>
            Send a GET request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to GET.</param>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Post(System.String,CS2PHPCryptography.PostPackageBuilder,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a POST request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="postVars">The list of variables to POST to the server.</param>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Post(System.String,CS2PHPCryptography.PostPackageBuilder)">
            <summary>
            Send a POST request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="postVars">The list of variables to POST to the server.</param>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Post(System.String,System.String)">
            <summary>
            Send a POST request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="data">The data to POST.</param>
        </member>
        <member name="M:CS2PHPCryptography.HttpControl.Post(System.String,System.String,CS2PHPCryptography.ProxySettings)">
            <summary>
            Send a POST request to a web page. Returns the contents of the page.
            </summary>
            <param name="url">The address to POST to.</param>
            <param name="data">The data to POST.</param>
        </member>
        <member name="M:CS2PHPCryptography.PostPackageBuilder.AddVariable(System.String,System.String)">
            <summary>
            Add a variable to the post packet.
            </summary>
            <param name="postVariableName">The variable name that will be posted.</param>
            <param name="postVariableValue">The value of the variable.</param>
        </member>
        <member name="P:CS2PHPCryptography.PostPackageBuilder.PostDataString">
            <summary>
            The actual string that can be used as the data of the post request.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.#ctor">
            <summary>
            Create a secure connection with a PHP script.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.SetRemotePhpScriptLocation(System.String)">
            <summary>
            Set the location of the PHP script to use in this secure connection.
            </summary>
            <param name="phpScriptLocation">The URL of the php script to contact.</param>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.EstablishSecureConnectionAsync">
            <summary>
            Start a secure connection in the background. The OnConnectionEstablished event will be raised upon sucessful connection.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.SendMessageSecure(System.String)">
            <summary>
            Send an encrypted message to the remote PHP script and wait for a secure response.
            </summary>
            <param name="message">The message to send.</param>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.CloseConnection">
            <summary>
            Securely close the connection. This will also tell the PHP server to destroy the session keys it has.
            </summary>
        </member>
        <member name="M:CS2PHPCryptography.SecurePHPConnection.SendMessageSecureAsync(System.String)">
            <summary>
            Send an encrypted message to the remote PHP script and wait for a secure response by way of OnResponseReceived.
            </summary>
            <param name="message">The message to send.</param>
        </member>
        <member name="E:CS2PHPCryptography.SecurePHPConnection.OnConnectionEstablished">
            <summary>
            Event raised when a secure connection has been established with the remote PHP script.
            </summary>
        </member>
        <member name="E:CS2PHPCryptography.SecurePHPConnection.OnResponseReceived">
            <summary>
            Event raised when an encrypted transmission is received as a response to something you sent.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.SecurePHPConnection.PHPScriptLocation">
            <summary>
            Gets the location of the PHP script that we are communicating with.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.SecurePHPConnection.SecureConnectionEstablished">
            <summary>
            Gets whether a secure connection has been established.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.SecurePHPConnection.OKToSendMessage">
            <summary>
            Gets whether it is OK to send a message right now. A connection must be established, and there must be no other pending transmissions.
            </summary>
        </member>
        <member name="P:CS2PHPCryptography.ResponseReceivedEventArgs.Response">
            <summary>
            The decrypted response from the remote PHP script.
            </summary>
        </member>
    </members>
</doc>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
United States United States
Scott enjoys working on proof-of-concept projects for the sake of learning new and interesting ways to solve problems.

Comments and Discussions