Welcome to the Xceed Community | Help
Community Search  
More Search Options

Decrypt from string

Sort Posts: Previous Next
  •  08-07-2007, 4:48 AM Post no. 6182

    Decrypt from string

    Hi there.

    Maybe im missing something but can any one help me to decrypt a "toSting" ASCII to nornal readable text.

    It works when i'm using to encrypt method "toString" but when i'm want to decrypt it is also sows garbage.

    Thanks
    Gerald
  •  08-08-2007, 9:57 AM Post no. 6183 in reply to 6182

    Re: Decrypt from string

    Here is a little sample on how to encrypt and decrypt with the RSA encryption method:

    <code>
    private object pubkey;
    private object prikey;

    static void Main( string[] args )
    {
    try
    {
    Program start = new Program();
    start.run();
    }
    catch( Exception ex )
    {
    Console.WriteLine( ex.ToString() );
    }
    finally
    {
    Console.WriteLine( "Fin" );
    Console.ReadLine();
    }
    }

    private void run()
    {
    generateKey();
    string test = encryptFunctionStringOnly( "I'm testing the encryption module, with string only" );
    string message = decryptFunctionStringOnly( test );

    Console.WriteLine( "After Decryption:\n" + message );
    }

    private void generateKey()
    {
    XceedEncryptionLib.XceedEncryption encrypt = new XceedEncryptionLib.XceedEncryption();
    encrypt.License( "CRY11-GRT9A-J7X75-BNAA" );

    XceedEncryptionLib.XceedRSAEncryptionMethod rsa = new XceedEncryptionLib.XceedRSAEncryptionMethod();

    try
    {
    object seed = null;
    rsa.SetRandomKeyPair( 1024, ref seed );
    prikey = rsa.get_PrivateKey();
    pubkey = rsa.get_PublicKey();
    }
    catch( System.Runtime.InteropServices.COMException except )
    {
    Console.WriteLine( except.ToString() );
    }
    }

    private string encryptFunctionStringOnly( string message )
    {
    Console.WriteLine( "Before Encryption:\n" + message );
    string encryptKey;
    XceedEncryptionLib.XceedEncryption encrypt = new XceedEncryptionLib.XceedEncryption();
    encrypt.License( "CRY11-GRT9A-J7X75-BNAA" );
    XceedEncryptionLib.XceedRSAEncryptionMethod rsa = new XceedEncryptionLib.XceedRSAEncryptionMethod();
    object encryptedData = ( object )"";

    try
    {
    rsa.set_PublicKey( ref pubkey );

    encrypt.EncryptionMethod = rsa;
    object data = ( object )message;


    encryptedData = encrypt.Encrypt( ref data, true );
    encryptKey = encrypt.ToString( ref encryptedData );
    }
    catch( System.Runtime.InteropServices.COMException except )
    {
    Console.WriteLine( except.ToString() );
    }

    return Convert.ToBase64String( ( byte[] )encryptedData );
    }

    private string decryptFunctionStringOnly( string message )
    {
    XceedEncryptionLib.XceedEncryption encrypt = new XceedEncryptionLib.XceedEncryption();
    encrypt.License( "CRY11-GRT9A-J7X75-BNAA" );
    XceedEncryptionLib.XceedRSAEncryptionMethod rsa = new XceedEncryptionLib.XceedRSAEncryptionMethod();
    string Output = "";
    System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();

    try
    {
    rsa.set_PublicKey( ref pubkey );
    rsa.set_PrivateKey( ref prikey );
    encrypt.EncryptionMethod = rsa;
    object encryptedData = ( object )Convert.FromBase64String( message );//enc.GetBytes( message );
    Output = enc.GetString( ( byte[] )encrypt.Decrypt( ref encryptedData, true ) );
    }
    catch( System.Runtime.InteropServices.COMException except )
    {
    Console.WriteLine( except.ToString() );
    }
    return ( string )Output;
    }
    </code>
    Charles Bérubé-Rémillard
    Technical Support
    Xceed Software Inc.
  •  08-10-2007, 4:50 AM Post no. 6184 in reply to 6183

    Re: Decrypt from string

    owZit.

    The vb.net example works great but the project that we working on in a vb6 application. And as you know vb6 does not support the base64 function.

    So is there any other way of converting the string without creating a new base64 function.

    NB: The vb6 example using the AES encrypts works but I want to keep the hex value constant. It must keep the same value each time.

    Thanks
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.