
Back to Blog index.
It is sometimes necessary to calculate hash values, and personally I prefer the MD5 algorithm.
I once had an Win32 MD5 implementation in Delphi code, but now with .NET, I don't need to write the code myself anymore.
Instead, I can use simple code like the following. The idea is to read an input string from a textbox, and show the hexadecimal hash string in another:
procedure MyForm.Button1_Click(sender: System.Object; e: System.EventArgs); Var InputBytes : Array of Byte; AE : System.Text.ASCIIEncoding; MD5 : System.Security.Cryptography.MD5CryptoServiceProvider; HashBytes : Array of Byte; begin AE := System.Text.ASCIIEncoding.Create(); InputBytes := AE.GetBytes(TextBox1.Text); MD5 := System.Security.Cryptography.MD5CryptoServiceProvider.Create(); HashBytes := MD5.ComputeHash(InputBytes); TextBox2.Text := ByteArrayToHexString(HashBytes); end;
Here, the code uses the MD5CryptoServiceProvider class from the System.Security.Cryptography namespace, as indicated by the Microsoft KB article 307020.
Finally, you need a way to convert a byte array to a hexadecimal string:
function MyForm.ByteArrayToHexString(Arr: array of Byte): String;
Var
SB : System.Text.StringBuilder;
B : Byte;
I : Integer;
begin
SB := System.Text.StringBuilder.Create(&Array(Arr).Length*2);
For I := 0 to System.&Array(Arr).Length-1 do Begin
B := Arr[I];
SB.Append(B.ToString('X2'));
End;
Result := SB.ToString();
end;
I would love to see a simple way of doing this conversion, but I'm yet to find a class to convert a byte array to a hex string.
Time flies so fast that I almost forgot to update my web pages to contain the details about my latest magazine articles.
The most recent Tietokone magazine has two of my articles, one about Social Networking, and the other about Windows updates and service packs.
Also, my co-operation with the Finnish Prosessori magazine started in a good way, and my very first column for this magazine appeared on the first issue of the year.
Gotcha! Last week I found myself scratching my head because NUnit didnt' find any tests in my test DLL.
Today I found the reason: when loading the tested DLL from a network drive, NUnit won't find any tests in the DLL. But, no error message is given!
Naturally, this is a Code Access Security (CAS) thing and can be configured, but it would be extremely nice if NUnit would at least report something...
Windows Installer technology has always been interesting in my mind, and it is interesting to read about it. MSDN has a new article about this technology.
For example, the article speaks about the "Orca" development tool that can edit .MSI files directly. This tool is part of the Platform SDK, but must be separately installed (search your hard disc for "Orca.msi").
The article also speaks about the ClickOnce deployment strategy that is useful for many .NET applications.
I tried creating some simple unit tests with NUnit 2.2 that comes with Delphi 2005, but unfortunately I couldn't get NUnit to recognize my C# libraries. The problem was simply that the attribute TestFixture could not be found, though ILDASM properly shows it.
I just created a simple C# library with Visual Studio .NET, and that worked just fine.
I need to investigate more why this happens with Delphi.
Data access is an important part of any business application, and on Microsoft platforms there are many ways to access data.
MSDN has a recent article about the roadmap of the Microsoft data access technologies. It is good to know what will happen to for example ADO, and how ADO.NET will evolve.
The interesting thing for Delphi developers is that the SQL Server access library DB-Library is now considered obsolete. My assumption is that dbExpress uses this library, so I wonder what is the future of this API.
I'd say it would be best for Borland to drop all those "new" data access layers, and concentrate on ADO.NET.
Awesome engineering work again from both NASA's and ESA's team: the Huygens space probe was alive on the alien surface for several hours.
The pictures flow to Earth as I write, and I'm waiting to see more of them than those three that are presently available on the Internet.
First the Mars rovers and then this. And a comet crasher (Deep Impact) soon. Quite a show, and no need to go to movies, even!
Resistance is futile. You might recall my earlier post about Dreamweaver MX 2004 messing up ASP.NET pages developed with Delphi 2005 or Visual Studio .NET 2003.
I've now come to the conclusion that it is not possible to properly combine Dreamweaver templates (.DWT files) and Delphi's ASP.NET visual designer.
Shortly put, Delphi insists on certain order of the HTML, HEAD and TITLE tags, which isn't suitable in Dreamweaver's mind. The result is a ASPX page that is part of the template, but cannot be updated to reflect changes in the template file.
Tough luck, it seems.
Sometimes aimless wandering on the Internet proves to be fruitful. This time, I found an interesting desing and refactoring tool for Visual Studio .NET called Flywheel.
The product by Velocitis Inc. appears to already be at version 7.2, which means it cannot be a very young product. Probably.
Nonetheless, I'm again sharing the link in case you find the product interesting.
I did some tests today in the area of HTML layouts and font sizes.
The web site I'm working on currently uses XHTML and CSS 2 stylesheets extensively, but the problem is that Delphi 2005 (or Visual Studio .NET for that matter) doesn't like the layout -- it is too complex.
So, I converted some of the pages back to HTML 4.0, and now Delphi likes them better. Also, my research showed that there are no problems with DIV tags, which appear to work fine. So no more layouts with tables, which is fine.
However, font sizes still give me trouble. When I specify a font size in the CSS file and use the browser's View/Text Size command to change the font sizes on the fly, the change is way too dramatic in IE. But Firefox on the other hand works better.
I don't know if this is the best solution or not, but I'm thinking of using the "pt" i.e. absolute point sizes in the stylesheet. This way, the text size cannot be changed in IE, but it still works okay in Firefox.
Yes, this is something that is not recommended by the specs, but the thing is that not so many users are aware of this setting in their browsers. If somebody for some reason has the "Largest" setting in the their browser and then goes to our site, the result looks really bad. This is what I want to avoid.
A friend of mine was kind enough to lend me a copy of Dan Brown's novel "The Da Vinci Code".
The book is a great adventure that includes brain-teasing problem solving, and also gives a great overview of the history of the Christian religion as we know it.
The only thing with this book is that it is, no less than a blockbuster. Such books need to grab a large audience, which means the book is easy to read, uses simple vocabulary, and is fast-paced. Much like a movie.
Having lately read literature classics only, this book gives itself much easier, a style which I personally dislike. However, this doesn't mean you shouldn't read the book, on the contrary.
Oh, the book also mentions some of the world's most interesting mathematical equations like the Fibonacci sequence. On the web, there's an excellent introduction to these numbers, which I can also recommend.
And speaking of math, MathSoft also has a web site devoted to the most well-known mathematical constants of all times, including the golden section.
› Blog Archive