C 之 AES加密原始碼

2021-09-07 03:51:04 字數 2401 閱讀 1287

using

system;

using

system.collections.generic;

using

system.linq;

using

system.web;

using

exam.encryptprivate;

using

system.text;

using

system.security.cryptography;

//////

aes加密、解密,金鑰長度256,金鑰長度不大於32個位元組

///

public

class

aescryptohelper

set

}private

bool

m_containkey;

//////

true:密文中包含金鑰

///false:密文中不包含金鑰

///

public

bool

containkey

set

}public

aescryptohelper()

public aescryptohelper(bool containkey):this

()

private

string encrypt(string s_crypto, byte key, byte

iv)s_encryped +=byte2hexstring(encrypted);

return

s_encryped;

}catch

(exception ex)

}//////

指定金鑰對明文進行aes加密

///

///明文

///加密金鑰

///public

string encrypt(string s_crypto, string

s_key)

key =string2byte(s_key.padright(key.length));

iv =string2byte(crypto_iv.padright(iv.length));

return

encrypt(s_crypto, key, iv);

}//////

動態生成金鑰,並對明文進行aes加密

///

///明文

///public

string encrypt(string

s_crypto)

private

string decrypt(string s_encrypted, byte key, byte

iv)catch

(exception ex)

}//////

從密文中解析出金鑰,並對密文進行解密

///

///密文

///public

string decrypt(string

s_encrypted)

if(m_containkey)

key =hexstring2byte(s_key);

iv =string2byte(crypto_iv.padright(iv.length));

return

decrypt(s_encrypted, key, iv);

}//////

指定金鑰,並對密文進行解密

///

///密文

///金鑰

///public

string decrypt(string s_encrypted, string

s_key)

key =string2byte(s_key.padright(key.length));

iv =string2byte(crypto_iv.padright(iv.length));

if(m_containkey)

return

decrypt(s_encrypted, key, iv);

}private

string byte2hexstring(byte

bytes)

", b);

}return

sb.tostring();

}private

byte hexstring2byte(string

hex)

return

bytes;

}private

byte string2byte(string

str)

private

string byte2string(byte

bytes)

}

C 之 AES加密原始碼

using system using system.collections.generic using system.linq using system.web using exam.encryptprivate using system.text using system.security.cry...

C 加密解密原始碼

using system using system.io using system.text using system.security.cryptography namespace x 獲取crypto例項 public static crypto instance return crypto.i...

C 加密解密 AES

using system namespace encrypt aes解密 需要解密字串 解密後字串 public static string decrypt string str aes加密 需要加密的字串 32位金鑰 加密後的字串 public static string encrypt stri...