密碼學(xué)的歷史可以追溯到古埃及和古希臘時(shí)期,當(dāng)時(shí)使用的是簡(jiǎn)單的替代密碼和移位密碼。隨著計(jì)算機(jī)和網(wǎng)絡(luò)技術(shù)的發(fā)展,密碼學(xué)也發(fā)展成為一門重要的科學(xué)。

20世紀(jì)50年代,數(shù)學(xué)家科爾·貝爾發(fā)明了第一種數(shù)學(xué)原理上安全的密碼算法- RSA算法。這個(gè)算法基于數(shù)論的難題,使用非對(duì)稱密鑰加密,在安全性和效率上都得到了很大的提高。

70年代,已經(jīng)有了許多基于對(duì)稱密鑰的加密算法,如 DES,但是這些算法的密鑰長度較短,安全性較低。

80年代,非對(duì)稱密鑰算法和對(duì)稱密鑰算法相結(jié)合的算法如 RSA 和 DES 的組合算法出現(xiàn)。

90年代,AES(高級(jí)加密標(biāo)準(zhǔn))算法誕生,這是一種基于對(duì)稱密鑰的算法,密鑰長度更長,安全性更高。

 

加密算法通常無需自己編寫,常見的密碼算法開源庫包括:

  1. OpenSSL – 支持多種密碼算法,如 AES, DES, RSA, ECC 等。
  2. libsodium – 一個(gè)輕量級(jí)的密碼算法庫,支持加密、解密、簽名、驗(yàn)簽、密鑰交換等操作。
  3. Botan – 一個(gè)多算法的密碼庫,支持常見的密碼算法,如 AES, DES, RSA, ECC 等。
  4. Crypto++ – 一個(gè)功能強(qiáng)大的密碼算法庫,支持多種密碼算法,如 AES, DES, RSA, ECC 等。
  5. pycrypto – python 的密碼算法庫,支持常見的密碼算法,如 AES, DES, RSA, ECC 等。

 

除了上述 這些開源算法,Windows操作系統(tǒng)提供了多種加密API供開發(fā)人員使用,其中一些常用的加密API如下:

  1. CryptoAPI:這是Windows操作系統(tǒng)內(nèi)置的加密API,支持常見的對(duì)稱加密算法和非對(duì)稱加密算法,如 AES, DES, RSA, ECC 等。
  2. CNG(Cryptography Next Generation) API:這是Windows Vista及更高版本提供的加密API,支持更多的加密算法和更高級(jí)的加密特性,并且兼容CryptoAPI。
  3. Windows Data Protection API(DPAPI):這是Windows提供的用于保護(hù)本地?cái)?shù)據(jù)的API,可以用于加密文件和密碼。
  4. Windows Hello: Windows Hello 是 Windows 10 內(nèi)置的生物識(shí)別技術(shù),支持指紋識(shí)別,面部識(shí)別和眼睛識(shí)別,可以用于驗(yàn)證用戶的身份。

這些API都有自己的特點(diǎn)和適用場(chǎng)景,開發(fā)人員可以根據(jù)需要選擇使用。

 

在C#中調(diào)用Windows加密API可以使用Win32 API或者.NET Framework中的類庫來實(shí)現(xiàn)。例如,下面是使用CryptoAPI進(jìn)行文件加密的示例代碼:

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptAcquireContext(
ref IntPtr hProv,
string pszContainer,
string pszProvider,
int dwProvType,
uint dwFlags);

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptCreateHash(
IntPtr hProv,
int algId,
IntPtr hKey,
uint dwFlags,
ref IntPtr phHash);

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptHashData(
IntPtr hHash,
byte[] pbData,
int dwDataLen,
uint dwFlags);

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptDeriveKey(
IntPtr hProv,
int algId,
IntPtr hBaseData,
uint dwFlags,
ref IntPtr phKey);

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptEncrypt(
IntPtr hKey,
IntPtr hHash,
bool final,
uint dwFlags,
byte[] pbData,
ref int pdwDataLen,
int dwBufLen);

[DllImport(“advapi32.dll”, SetLastError = true)]
public static extern bool CryptDecrypt(
IntPtr hKey,
IntPtr hHash,
bool final,
uint dwFlags,
byte[] pbData,
ref int pdwDataLen);

[DllImport(“advapi32.dll”, SetLast

 

在VB中調(diào)用Windows加密API可以使用Win32 API或者.NET Framework中的類庫來實(shí)現(xiàn)

使用Win32 API,可以使用 Declare 關(guān)鍵字來定義并調(diào)用Windows加密API。例如,下面是使用CryptoAPI進(jìn)行文件加密的示例代碼:

Private Declare Function CryptAcquireContext Lib “advapi32.dll” Alias “CryptAcquireContextA” (ByRef phProv As Long, ByVal pszContainer As String, ByVal pszProvider As String, ByVal dwProvType As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptCreateHash Lib “advapi32.dll” (ByVal hProv As Long, ByVal Algid As Long, ByVal hKey As Long, ByVal dwFlags As Long, ByRef phHash As Long) As Long
Private Declare Function CryptHashData Lib “advapi32.dll” (ByVal hHash As Long, ByVal pbData As String, ByVal dwDataLen As Long, ByVal dwFlags As Long) As Long
Private Declare Function CryptDeriveKey Lib “advapi32.dll” (ByVal hProv As Long, ByVal Algid As Long, ByVal hBaseData As Long, ByVal dwFlags As Long, ByRef phKey As Long) As Long
Private Declare Function CryptEncrypt Lib “advapi32.dll” (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, ByRef pdwDataLen As Long, ByVal dwBufLen As Long) As Long
Private Declare Function CryptDecrypt Lib “advapi32.dll” (ByVal hKey As Long, ByVal hHash As Long, ByVal Final As Long, ByVal dwFlags As Long, ByVal pbData As String, ByRef pdwDataLen As Long) As Long
Private Declare Function CryptReleaseContext Lib “advapi32.dll” (ByVal hProv As Long, ByVal dwFlags As Long) As Long

 

使用.NET Framework中的類庫,可以使用 System.Security.Cryptography 命名空間中的類和方法來實(shí)現(xiàn)加密。例如,下面是使用AES算法進(jìn)行文件加密的示例代碼:

Dim AES As New System.Security.Cryptography.AesCryptoServiceProvider
AES.Key = System.Text.Encoding.ASCII.GetBytes(“YourKey”)
AES.IV = System.Text.Encoding.ASCII.GetBytes(“YourIV”)

‘ Encryption
Dim encryptor As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor()
Using msEncrypt As New System.IO.

 

★關(guān)于WorkWin公司電腦監(jiān)控軟件★

WorkWin的使命是打造Work用途的Windows 電腦系統(tǒng),有效規(guī)范員工上網(wǎng)行為,讓老板知道員工每天在做什么(監(jiān)控包括屏幕、上網(wǎng)在內(nèi)的一舉一動(dòng)),限制員工不能做什么(禁止網(wǎng)購、游戲、優(yōu)盤等)。

WorkWin基于純軟件設(shè)計(jì),非常容易使用,無需添加或改動(dòng)任何硬件,使用一臺(tái)管理機(jī)監(jiān)控全部員工機(jī)電腦。歷經(jīng)南京網(wǎng)亞十余年精心打造,此時(shí)此刻每天都有成千上萬企業(yè)電腦正在運(yùn)行WorkWin,選擇WorkWin選擇“贏”。

WorkWin介紹

WorkWin監(jiān)控首頁 短視頻講解 下載免費(fèi)試用版

版權(quán)所有,南京網(wǎng)亞計(jì)算機(jī)有限公司 。本文鏈接地址: C# 、VB調(diào)用Windows自帶的加密算法API