VB.NET: 2008年6月アーカイブ

MD5やSHA1のハッシュ値を取得するには、名前空間System.Security.Cryptographyの以下のクラスを利用します。
MD5: MD5CryptoServiceProvider クラス
SHA1:SHA1CryptoServiceProvider クラス

Dim str As String = "TEST"
Dim md5 As New MD5CryptoServiceProvider
Dim sha1 As New SHA1CryptoServiceProvider

Dim byteValue() As Byte = Encoding.UTF8.GetBytes(str)
Dim hashValue() As Byte = md5.ComputeHash(byteValue)
Dim result As StringBuilder = New StringBuilder()
Dim b As Byte

For Each b In hashValue
    result.Append(b.ToString("x2"))
Next
MessageBox.Show(result.ToString, "ハッシュ結果", MessageBoxButtons.OK)
MD5CryptoServiceProvider クラス
http://msdn.microsoft.com/ja-jp/library/system.security.cryptography.md5cryptoserviceprovider(VS.80).aspx

SHA1の場合は、
VB.NET(VB2005)アプリからのHttpアクセスを行うには、System.NET名前空間のWebClientクラスを用います。

Sub Main()
    Dim wc As System.Net.WebClient = New System.Net.WebClient()
    Dim st As System.IO.Stream = wc.OpenRead("http://xxxx/test/default.aspx")
    st.Close()
End Sub
WebClient クラス
http://msdn.microsoft.com/ja-jp/library/system.net.webclient(VS.80).aspx

このアーカイブについて

このページには、2008年6月以降に書かれたブログ記事のうちVB.NETカテゴリに属しているものが含まれています。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

VB.NET: 2008年6月: 月別アーカイブ

Powered by Movable Type 4.01