博客來網路書店查詢

書名

博客來網路書店查詢

星期日, 11月 25, 2007

RSACryptoServiceProvider 類別

使用由密碼編譯服務供應者 (CSP) 提供之 RSA 演算法的實作,執行非對稱加密和解密。這個類別無法被繼承。

Dim instance As RSACryptoServiceProvider

下列程式碼範例會使用 RSACryptoServiceProvider 類別,將字串加密成位元組陣列,然後再將位元組解密回字串。


Imports System
Imports System.Security.Cryptography
Imports System.Text

_

Class RSACSPSample


Shared Sub Main()
Try
'Create a UnicodeEncoder to convert between byte array and string.
Dim ByteConverter As New UnicodeEncoding()

'Create byte arrays to hold original, encrypted, and decrypted data.
Dim dataToEncrypt As Byte() = ByteConverter.GetBytes("Data to Encrypt")
Dim encryptedData() As Byte
Dim decryptedData() As Byte

'Create a new instance of RSACryptoServiceProvider to generate
'public and private key data.
Dim RSA As New RSACryptoServiceProvider()

'Pass the data to ENCRYPT, the public key information
'(using RSACryptoServiceProvider.ExportParameters(false),
'and a boolean flag specifying no OAEP padding.
encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(False), False)

'Pass the data to DECRYPT, the private key information
'(using RSACryptoServiceProvider.ExportParameters(true),
'and a boolean flag specifying no OAEP padding.
decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(True), False)

'Display the decrypted plaintext to the console.
Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData))
Catch e As ArgumentNullException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine("Encryption failed.")
End Try
End Sub


Public Shared Function RSAEncrypt(ByVal DataToEncrypt() As Byte, ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
Try
'Create a new instance of RSACryptoServiceProvider.
Dim RSA As New RSACryptoServiceProvider()

'Import the RSA Key information. This only needs
'toinclude the public key information.
RSA.ImportParameters(RSAKeyInfo)

'Encrypt the passed byte array and specify OAEP padding.
'OAEP padding is only available on Microsoft Windows XP or
'later.
Return RSA.Encrypt(DataToEncrypt, DoOAEPPadding)
'Catch and display a CryptographicException
'to the console.
Catch e As CryptographicException
Console.WriteLine(e.Message)

Return Nothing
End Try
End Function


Public Shared Function RSADecrypt(ByVal DataToDecrypt() As Byte, ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
Try
'Create a new instance of RSACryptoServiceProvider.
Dim RSA As New RSACryptoServiceProvider()

'Import the RSA Key information. This needs
'to include the private key information.
RSA.ImportParameters(RSAKeyInfo)

'Decrypt the passed byte array and specify OAEP padding.
'OAEP padding is only available on Microsoft Windows XP or
'later.
Return RSA.Decrypt(DataToDecrypt, DoOAEPPadding)
'Catch and display a CryptographicException
'to the console.
Catch e As CryptographicException
Console.WriteLine(e.ToString())

下列程式碼範例會使用 RSACryptoServiceProvider,將建立的金鑰資訊匯出到 RSAParameters 物件。


Try

'Create a new RSACryptoServiceProvider object.
Dim RSA As New RSACryptoServiceProvider()

'Export the key information to an RSAParameters object.
'Pass false to export the public key information or pass
'true to export public and private key information.
Dim RSAParams As RSAParameters = RSA.ExportParameters(False)


Catch e As CryptographicException
'Catch this exception in case the encryption did
'not succeed.
Console.WriteLine(e.Message)
End Try
Return Nothing
End Try
End Function
End Class

內容來源:微軟的MSDN

星期六, 11月 24, 2007

RegularExpressionValidato屬性:ValidationExpression

[ ]:
定義可接受的字元,例:
[a-z]表示可接受a~z等26個英文小寫字母、
[0-5]表示可接受0~5個數字、
[^ b-e]表示除了b~e之外,所有字元圴接受
(^符號為不接受的意思)、[abc]表可接受a,b,c三個小寫字母。)

{ }:
定義須輸入的字元數,例:
{3}表示須輸入3個字元、
{1,3}須輸入1~3個字元、
{n,}表接受n~無限多個字元。
所以
[A-C]{3}表必須輸入3個大寫字母、
[a-zA-z0-9]{1,9}表可輸入1~9個大小寫字母或數字。

.:
表任意的字元,例:
.{8}表可接受8個任意字元。

|:
表「或」的意思,例:
[a-c]{1}|[0-9]{2}表必須輸入a~c之間的一個小寫字母或2個數字。

( ):
此符號可有可無,目的是為了方便閱讀,例:
([A-B]) | ([a-z])加了括號是不是比 [A-B] | [a-z]更清楚看出 | 符號。
\:
若可接受的字元中包含上述符號,
則必須在特殊符號前加上\符號,例:可接受的字元包括[],則寫成 \[\]

星期四, 11月 15, 2007

遮罩

定義輸入遮罩

輸入遮罩定義可以包含分號分開的三個區段﹔例如,(999) 000-0000!;0;" "

區段

意義

第一個

輸入遮罩本身。

第二個

決定是否儲存文字顯示字元。

0 = 以輸入的值儲存文字字元

1 = 留空白 = 儲存只有輸入空白的字元

第三個

在輸入遮罩顯示為空白的字元。您可以使用任何字元﹔輸入 " " (雙引號、空格、雙引號) 來顯示一個空格。如果您在此區段留下空白,底線 (_) 就會被使用。

有效的輸入遮罩字元

Microsoft Access 解釋在輸入遮罩屬性定義的第一個部分字元如下列表格顯示。若要定義文字字元,請輸入沒有顯示在此表格的其他任何字元,包含空格和符號。若要定義下列字元的其中之一為文字字元,請在字元前面加上 \

字元

敘述

0

數字 (0 9,必須輸入﹔不允許加號〔+〕和減號〔-)

9

數字或空格 (不需輸入﹔不允許加號和減號)

#

數字或空格 (不需輸入﹔空白位置轉換成空格,允許加號和減號)

L

字母 (A Z,必須輸入)

?

字母 (A Z,選擇性輸入)

A

字母或數字 (必須輸入)

a

字母或數字 (選擇性輸入)

&

任何字元或空格 (必須輸入)

C

任何字元或空格 (選擇性輸入)

. , : ; - /

小數點位置與千、日期、和時間的分隔符號。 (實際使用的字元根據由按兩下 Windows [控制台] [國別設定] 所指定的國別設定。

<

使之後的所有字元轉換成小寫。

>

使之後的所有字元轉換成大寫。

!

使輸入遮罩由右至左的顯示,而不是由左至右。鍵入的字元通常由左至右填入遮罩內。您可在輸入遮罩的任何地方包含驚嘆號。

\

使之後的字元顯示成文字字元。用來使列在此資料表的任何字元顯示成文字字元 (例如, \A 就顯示成 A )

Password

設定輸入遮罩屬性為密碼這個字會建立密碼項目文字方塊。在文字方塊鍵入的任何字元會儲存為此字元,但會顯示為星號 (*)

星期三, 11月 14, 2007

javascript內的Date物件

function check(arg_intYear,arg_intMonth,arg_intDay)
{
//月數從0開始,所以要將參數減一
var objDate = new Date(arg_intYear,arg_intMonth-1,arg_intDay);
//檢查月份是否小於12大於1
if((parseInt(arg_intMonth) > 12) || (parseInt(arg_intMonth) < 1))
{
alert(arg_intYear+'/'+arg_intMonth+'/'+arg_intDay+' 月份不正確');
}
else
{
//如果objDate日數進位不等於傳入的arg_intDay,
//代表天數格式錯誤,另外月份進位也代表日期格式錯誤
if((parseInt(arg_intDay) != parseInt(objDate.getDate()))||(parseInt(arg_intMonth)!= parseInt((objDate.getMonth()+1))))
{
alert(arg_intYear+'/'+arg_intMonth+'/'+arg_intDay+ ' 天數不正確');
}
else
{
alert(arg_intYear+'/'+arg_intMonth+'/'+arg_intDay+ ' 日期格式正確');
}
}
}
所以下面可以嘗試看看會有怎樣的回應?

check(2007,2,29); //alert 天數不正確
checkDate(2008,2,29); //alert 日期格式正確
checkDate(2007,7,31); //alert 日期格式正確

CSS與Java Script

網頁其實是由很多的標籤,也就是<>這樣的符號組合而成。
每一個標籤都有他的定義與用途,比如說<img>代表的是圖形,
而<hr>代表的是水平線。
如果我想要自己定義標籤,那該怎麼作呢?
例如<a href>指的是超連結,這個標籤預設會有底線,
如果我希望他不要出現底線,那就得重新定義這個標籤,
而這個重新定義標籤,就是CSS樣式表。
所以您若於網頁原始碼內看到

<style type="text/css">
a {text-decoration:none}
</style>
這就是CSS的運用。

HTML語法只能靜態呈現圖文資料,而CSS則是重新定義標籤的功能,
而script是什麼呢?script指可讓網頁上的標籤與
使用者產生互動。
例如當我進入網頁,他就會秀出訊息,這就是script的功能。

<html>
<head>
<script type="text/javascript">
function message() {
alert(”歡迎光臨!”)
}
</script>
</head>
<body onload=”message()”>
</body>
</html>

CSS可以重新定義HTML的標籤,所以您也可以設計網頁文字呈現
在圖片檔案上面,您也可以引用、匯入已經設計好的CSS。
而script可以增加網頁與使用者之間的互動,也可搭配CSS,
搭配修改過的網頁標籤與使用者互動。

CSS與Script,是網頁裡蠻重要的兩個基本的元素,
細節部分,可參考巨匠電腦的以下課程:

1.如果您習慣使用FrontPage,可詢問以下兩個課程:
WH1活用網頁設計基礎FrontPage
WH2活用網頁設計應用FrontPage

2.如果您習慣使用Dreamwaver,可詢問以下兩個課程:
ID5Dreamweaver網頁設計
ID6Dreamweaver網頁應用
ID7Dreamweaver動態資料庫網站設計
ID8Dreamweaver動態網站進階應用篇

如果您沒有網頁基礎,建議您可到各分校旁聽,
由FrontPage或Dreamwaver擇一學習。