對稱加密 解密

2022-01-11 05:02:50 字數 1681 閱讀 7369

///

///加密

/// public

static

class

encrypting

//////

使用對稱演算法加密

/// ///

//////

public

static

string symmetricencrypts(string

str)

;//如需指定加密演算法,可在create()引數中指定字串

//create()方法中的引數可以是:des、rc2 system、rijndael、tripledes

//採用不同的實現類對iv向量的要求不一樣(可以用generateiv()方法生成),無引數表示用rijndael

algorithm = symmetricalgorithm.create();//

產生一種加密演算法

mstarget = new

memorystream();

//定義將資料流鏈結到加密轉換的流。

encstream = new

cryptostream(mstarget, algorithm.createencryptor(convert.frombase64string(getencryptkey()), kv), cryptostreammode.write);

encstream.write(inputdata,

0, inputdata.length);

encstream.flushfinalblock();

result =convert.tobase64string(mstarget.toarray());

}catch

(exception)

finally

return

result;

}//////

使用對稱演算法解密

/// ///

//////

public

static

string symmectricdecrypts(string

encryptstr)

;byte encryptdata =convert.frombase64string(encryptstr);

algorithm =symmetricalgorithm.create();

mstarget = new

memorystream();

decstream = new

cryptostream(mstarget, algorithm.createdecryptor(convert.frombase64string(getencryptkey()), kv), cryptostreammode.write);

decstream.write(encryptdata,

0, encryptdata.length);

decstream.flushfinalblock();

result =system.text.encoding.default.getstring(mstarget.toarray());

}catch

(exception)

finally

return

result;

}#endregion

}

對稱加密解密

幫助類 public class cryptohelper encryptor provider.createencryptor decryptor provider.createdecryptor initializes a new instance of the class.金鑰 public ...

對稱加密與解密

using system using system.collections.generic using system.linq using system.text using system.io using system.security.cryptography namespace encrypt...

對稱加密解密類

using system using system.collections.generic using system.web using system.security.cryptography using system.text using system.io using system.web.u...