Home Forums ActiveX components Xceed Encryption for ActiveX Decrypt from string

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #42969 |

    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

    Imported from legacy forums. Posted by Gerald (had 6879 views)

    Xceed Support
    Member
    Post count: 5658

    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>

    Imported from legacy forums. Posted by CharlesB (had 437 views)

    User (Old forums)
    Member
    Post count: 23064

    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

    Imported from legacy forums. Posted by Gerald (had 8739 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.