zoukankan
html css js c++ java
字符串加密方法
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Security.Cryptography;
using
System.IO;
namespace
Component
{
public
class
Security
{
public
Security()
{
}
//
默认密钥向量
private
static
byte
[] Keys
=
{
0x12
,
0x34
,
0x56
,
0x78
,
0x90
,
0xAB
,
0xCD
,
0xEF
}
;
/**/
///
<summary>
///
DES加密字符串
///
</summary>
///
<param name="encryptString">
待加密的字符串
</param>
///
<param name="encryptKey">
加密密钥,要求为8位
</param>
///
<returns>
加密成功返回加密后的字符串,失败返回源串
</returns>
public
static
string
EncryptDES(
string
encryptString,
string
encryptKey)
{
try
{
byte
[] rgbKey
=
Encoding.UTF8.GetBytes(encryptKey.Substring(
0
,
8
));
byte
[] rgbIV
=
Keys;
byte
[] inputByteArray
=
Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP
=
new
DESCryptoServiceProvider();
MemoryStream mStream
=
new
MemoryStream();
CryptoStream cStream
=
new
CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray,
0
, inputByteArray.Length);
cStream.FlushFinalBlock();
return
Convert.ToBase64String(mStream.ToArray());
}
catch
{
return
encryptString;
}
}
/**/
///
<summary>
///
DES解密字符串
///
</summary>
///
<param name="decryptString">
待解密的字符串
</param>
///
<param name="decryptKey">
解密密钥,要求为8位,和加密密钥相同
</param>
///
<returns>
解密成功返回解密后的字符串,失败返源串
</returns>
public
static
string
DecryptDES(
string
decryptString,
string
decryptKey)
{
try
{
byte
[] rgbKey
=
Encoding.UTF8.GetBytes(decryptKey);
byte
[] rgbIV
=
Keys;
byte
[] inputByteArray
=
Convert.FromBase64String(decryptString);
DESCryptoServiceProvider DCSP
=
new
DESCryptoServiceProvider();
MemoryStream mStream
=
new
MemoryStream();
CryptoStream cStream
=
new
CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray,
0
, inputByteArray.Length);
cStream.FlushFinalBlock();
return
Encoding.UTF8.GetString(mStream.ToArray());
}
catch
{
return
decryptString;
}
}
}
}
查看全文
相关阅读:
PHP查看IP时候能ping通
mysql把查询到不一样的记录插入到另一张表中
js本地预览图片
redis 扩展下载
mysql update select子查询
mysql view视图的简单使用....
两表联查关联字段我想查多个怎么办???
两表联查是关联字段的值位数不一样时怎么办???
使用PHP生成二维码(PHPQRCode)
.net初学之SerialPort串口类
原文地址:https://www.cnblogs.com/pw/p/615060.html
最新文章
MySQL 5.7.9 修改root用户初始密码、设置远程连接
bug
【基础组件19】redis入门(一)简介、哨兵模式、集群搭建、常用命令、性能高可用、高并发概述
【基础组件18】Apache Druid 0.14入门(一)简介、集群部署、使用kafka 构建实时数据摄取
【基础组件17】elasticsearch 入门(四) ik 中文分词器安装、数据类型、mapping
【基础组件16】elasticsearch 入门(三)ES核心概念
【基础组件15】elasticsearch 入门(二)Rest基本操作
【基础组件14】elasticsearch 6.8 入门(一)搜索引擎 ES原理概述
【基础组件14】Elasticsearch (二)
【基础组件12】Elasticsearch 6.8集群搭建+es-head安装+es-ik安装
热门文章
111
Maven学习笔记5:Maven属性、profile和资源过滤
Maven学习3(中央仓库)
Maven学习笔记2(坐标和依赖)
Maven学习笔记1(clean compile package install)
Maven 项目 启动时 解决3 字节的 UTF-8 序列的字节 3 无效
Executors创建的4种线程池的使用
在Java中使用Socket模拟客户端和服务端(多线程)
Java中十六进制转换 Integer.toHexString()
mysql给用户分配权限
Copyright © 2011-2022 走看看