AraCrypt – my favourite crypting algorithm.

It was 1998 and I developed a C++ project for our customer. At this time crypting algorithems hadn’t been a part of the programming language and therefore must be implemented by the developer himself. Another way was to spent lot of money to buy a library.

That was the time I found the AraCrypt algorithm from Darroll Walsh at www.codeproject.com. I was very impressed about the simplicity of this algorithem.

It only had one deficit, that was that a crypted string could contain /0 which was not very useful when working with null terminated strings … (That’s a thing I changed on AraCrypt.)

The use case I needed the AraCrypt algorithm was storing values in Ini Files, Registry and XML – you can say, I always used it to store configuration data. That’s why I added a conversion from binary to hex string and back, that was even more user-friendly.

… The project changed, but the good experience persists …

I must admit that I really missed that wonderful crypting algorithm. That’s why I decided to rewrite it for other programming languages. First for Visual Basic 6, after that PHP and than C#. I really ported it to every language I used in the following years.

As an example here’s the link for the PHP example: AraCrypt PHP

If I could arouse interest in you, you can download the AraCrypt porting for VB6, PHP and C# using the following link.
Download the AraCrypt portings.

Slow Oracle BLOB upload with C# .NET and how to speed up.

In our current development we had the problem that our document upload into the oracle database took very long. It was completly beyond the pale.

With our Oracle Specialist Carl Reitschuster we discovered that this must be a problem of the ADO .NET implementation of Oracle. The upload with the PL Developer took only about 2 seconds, but with our C# code it took 46 seconds for the same document upload.

We found out that the ADO .NET Driver for Oracle is very slow when the upload buffer is set at once.


/// <summary>
/// Examples the of slow upload. (about 46 seconds)
/// </summary>
public void ExampleOfSlowUpload ()
{
    startTime = DateTime.Now;
    transaction = oracle.BeginTransaction();
    OracleCommand  command  = new OracleCommand (uploadSQL, oracle);
    OracleParameter uploadParameter = new OracleParameter(":blob", OracleDbType.Blob, ParameterDirection.Input);
    uploadParameter.Value = uploadBuffer;
 
    command.Parameters.Add(uploadParameter);
    command.ExecuteNonQuery();
    transaction.Commit();
 
    Console.WriteLine("Slow upload took : " + new TimeSpan(DateTime.Now.Ticks - startTime.Ticks).TotalSeconds + " seconds");
}

After a long term of search we discovered a solution that splits the upload buffer to small chunks. With this hint we could speed up the upload from 46 seconds to 4 seconds at all.


/// <summary>
/// Examples the of fast upload. (about 4 seconds)
/// </summary>
public void ExampleOfFastUpload ()
{
    startTime = DateTime.Now;
    transaction = oracle.BeginTransaction();
    OracleCommand  command  = new OracleCommand (uploadSQL, oracle);
    OracleParameter uploadParameter = new OracleParameter(":blob", OracleDbType.Blob, ParameterDirection.Input);
    OracleBlob blob = new OracleBlob(oracle);   
 
    int startOffset = 0;           
    int writeBytes = 0;
 
    /*
    * ... now load the buffer in small chunks to Oracle
    */
    blob.BeginChunkWrite();
    do
    {
        writeBytes = startOffset+BUFFER_SIZE>uploadBuffer.Length? uploadBuffer.Length-startOffset : BUFFER_SIZE;
        blob.Write(uploadBuffer, startOffset, writeBytes);
        startOffset += writeBytes;
    } while (startOffset < uploadBuffer.Length);
    blob.EndChunkWrite();
 
    uploadParameter.Value = blob;
 
    command.Parameters.Add(uploadParameter);
    command.ExecuteNonQuery();
    transaction.Commit();
 
    Console.WriteLine("Fast upload took : " + new TimeSpan(DateTime.Now.Ticks - startTime.Ticks).TotalSeconds + " seconds");
}

The complete demo solution can be downloaded from here:
OracleUploadProblem.zip