Html源代码图片解密,通过图片加密、解密文件
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO; //
using System.Security.Cryptography;
namespace _65利用图片加密文件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//加密
private void button3_Click_1(object sender, EventArgs e)
{
try
{
if (pictureBox1.ImageLocation==null)
{ MessageBox.Show("请选择一幅图片用于加密"); return; }
if (textBox1.Text == "")
{ MessageBox.Show("请选择加密文件路径"); return; }
//图片流
FileStream fsPic = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
//加密文件流
FileStream fsText = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
//初始化Key IV
byte[] bykey = new byte[16];
byte[] byIv = new byte[8];
fsPic.Read(bykey, 0, 16);
fsPic.Read(byIv, 0, 8);
//临时加密文件
string strPath = textBox1.Text;//加密文件的路径
int intLent = strPath.LastIndexOf("\\") 1;
int intLong = strPath.Length;
string strName = strPath.Substring(intLent, intLong - intLent);//要加密的文件名称
string strLinPath = "C:\\" strName;//临时加密文件路径
FileStream fsOut = File.Open(strLinPath, FileMode.Create, FileAccess.Write);
//开始加密
RC2CryptoServiceProvider desc = new RC2CryptoServiceProvider();//desc进行加密
BinaryReader br = new BinaryReader(fsText);//从要加密的文件中读出文件内容
CryptoStream cs = new CryptoStream(fsOut, desc.CreateEncryptor(bykey, byIv), CryptoStreamMode.Write);//写入临时加密文件
cs.Write(br.ReadBytes((int)fsText.Length), 0, (int)fsText.Length);//写入加密流
cs.FlushFinalBlock();
cs.Flush();
cs.Close();
fsPic.Close();
fsText.Close();
fsOut.Close();
File.Delete(textBox1.Text.TrimEnd());//删除原文件
File.Copy(strLinPath, textBox1.Text);//复制加密文件
File.Delete(strLinPath);//删除临时文件
MessageBox.Show("加密成功");
pictureBox1.ImageLocation = null;
textBox1.Text = "";
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
//解密
private void button4_Click_1(object sender, EventArgs e)
{
try
{
//图片流
FileStream fsPic = new FileStream(pictureBox1.ImageLocation, FileMode.Open, FileAccess.Read);
//解密文件流
FileStream fsOut = File.Open(textBox1.Text, FileMode.Open, FileAccess.Read);
//初始化Key IV
byte[] bykey = new byte[16];
byte[] byIv = new byte[8];
fsPic.Read(bykey, 0, 16);
fsPic.Read(byIv, 0, 8);
//临时解密文件
string strPath = textBox1.Text;//加密文件的路径
int intLent = strPath.LastIndexOf("\\") 1;
int intLong = strPath.Length;
string strName = strPath.Substring(intLent, intLong - intLent);//要加密的文件名称
string strLinPath = "C:\\" strName;//临时解密文件路径
FileStream fs = new FileStream(strLinPath, FileMode.Create, FileAccess.Write);
//开始解密
RC2CryptoServiceProvider desc = new RC2CryptoServiceProvider();//desc进行解密
CryptoStream csDecrypt = new CryptoStream(fsOut, desc.CreateDecryptor(bykey, byIv), CryptoStreamMode.Read);//读出加密文件
BinaryReader sr = new BinaryReader(csDecrypt);//从要加密流中读出文件内容
BinaryWriter sw = new BinaryWriter(fs);//写入解密流
sw.Write(sr.ReadBytes(Convert.ToInt32(fsOut.Length)));//
sw.Flush();
sw.Close();
sr.Close();
fs.Close();
fsOut.Close();
fsPic.Close();
csDecrypt.Flush();
File.Delete(textBox1.Text.TrimEnd());//删除原文件
File.Copy(strLinPath, textBox1.Text);//复制加密文件
File.Delete(strLinPath);//删除临时文件
MessageBox.Show("解密成功");
pictureBox1.ImageLocation = null;
textBox1.Text = "";
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
//选择图片
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
pictureBox1.Load(openFileDialog1.FileName);
}
//选择文本
private void button2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
textBox1.Text = openFileDialog1.FileName;
}
}
}
Html源代码图片解密,通过图片加密、解密文件相关推荐
- nodejs java rsa_NodeJS加密解密及node-rsa加密解密用法详解
要用nodejs开发接口,实现远程调用,如果裸奔太危险了,就在网上找了一下nodejs的加密,感觉node-rsa挺不错的,下面来总结一下简单的rsa加密解密用法 初始化环境 新建一个文件夹 node ...
- 关于图片转base64的加密解密
这个插件裁剪完的图片都是 base64 加密的字符串,上传头像也就涉及到了如何把加密的字符串转换成图片的问题. 以下是代码: /*** @Description: 将base64编码字符串转换为图片* ...
- aes js 加盐值 解密_crypto-js aes加密解密
安装 npm install crypto-js --save unit.js import CryptoJS from "crypto-js"; //秘钥 const CRYPT ...
- ios php rsa加密解密,php rsa加密解密使用详解
第一条命令生成原始 RSA私钥文件 rsa_private_key.pem,第二条命令将原始 RSA私钥转换为 pkcs8格式,第三条生成RSA公钥 rsa_public_key.pem 从上面看出通 ...
- java php aes加密解密_php aes 加密解密可与java对接
php aes 加密解密可与java对接 博主:liu1693 发表时间:2017-02-23 16:52:27 浏览量:100 class Encrypt{ //加密方法 public static ...
- js怎么实现对html代码加密解密,javascript脚本加密解密及HTML转JS
HTML & Javascript 相互转换 < body > HTML & Javascript 输入 & 输出 < br > < script ...
- DES加密解密与AES加密解密
× 目录 [1]AES加密算法和DES加密算法的效率比较 [2]AES和DES加密解密代码 随着开发时间的变长,当初认为比较难的东西,现在渐渐也就变的不那么难了!特别对于一些经常很少使用的类,时间长了 ...
- java 加密解密编程,java 加密解密容易实现
当前位置:我的异常网» 编程 » java 加密解密容易实现 java 加密解密容易实现 www.myexceptions.net 网友分享于:2013-10-27 浏览:3次 java 加密解密 ...
- java公钥加密私钥解密过程_GPG加密解密过程
GPG加密解密过程 一.Linux系统下 1.安装 yum安装 [root@POC-ORACLE ~]# yum install gnupg 下载安装包安装 https://www.gnupg.org ...
- 加密解密_作业-加密解密程序
# 加密解密程序'''作业:自己写一个加密程序,能够加密的内容是英文和汉字.同时加密并且解密就是说,一段话中既有中文又有英文,标点符号不用处理.加密规则,获取ascii码数字,中间用|分割# 思路提示 ...
最新文章
- linux跨主机复制文件
- springboot mysql行锁_SpringBoot基于数据库实现简单的分布式锁
- [转]ubuntu linux下DNS重启后丢失(不是Network-manager造成的情况)
- 2019年上海市数学建模讲座(3)微分方程建模方法
- 安卓项目打开有时候manifests不见了_【必看】暴力0鲁项目详细操作及玩法如何跳过广告,不分享群等...
- Qt Creator基本快捷键
- 《剑指offer》斐波那契数列
- 如何利用脚本方法清除文本框中汉字,从而保留英文字母和数字等
- Kung Fu Panda: Legends of Awesomeness 2
- maven netty 配置_Netty是业界最流行的NIO框架之一:初识Netty
- python 非线性规划_支持向量机:Stata 和 Python 实现
- index android js,reactjs – React Native项目没有index.ios.js或index.android.js
- sql2005性能优化(在32位系统上突破2G内存使用量的方法)
- Java任务调度框架Quartz入门
- 50道编程题(有精力的同学看看)
- postman自动化测试
- gzdeflate函数_php 压缩函数gzencode gzdeflate gzcompress
- 企业对计算机类专业人才培养方案,应用型本科计算机科学与技术专业人才培养方案探讨...
- 网络服务器充斥大量信息,使网络服务器中充斥着大量要求回复的信息,消耗带宽,导致网络或系统停止正常服务,这属于什么攻 - 普法考试题库问答...
- html2canvas 截图丢失部分元素的问题
热门文章
- 【微信小程序控制硬件③】 从软件到硬件搭建一个微信小程序控制esp8266的项目,自定义通讯协议,为面试职位和比赛项目加分!
- java读pdf一行_java读与pdf白件的时分呈现非常
- 微信小程序图片(头像)裁剪工具we-cropper含2d版-完整版
- 哈工大2022春CSAPP大作业-程序人生(Hello‘s P2P)
- angular.js 错误: Error [$injector:unpr] 原因
- 汉字转拼音 - 输入汉字获取其拼音
- 三维地图开发平台-支持离线地图开发
- 用vb.net写一个简易的RSS阅读器
- c#超火表白小程序(含代码教程)
- 鸿蒙小型系统内核Liteos-a开发指南