導航:首頁 > 文檔加密 > 簡單加密的代碼實現

簡單加密的代碼實現

發布時間:2022-01-12 21:53:58

A. ct語言編程中簡單加密計算的程序代碼參考

你好!你先用什麼加密方式,程序可以嘗試完成

B. 用c++編寫一個簡單的文件加密程序

我自己想寫一個加密的方式
還覺得這個挺難的。
如果真的沒有太高的c++這一塊的基礎的話。
真的是沒法做到,因為代碼比較難寫的。
只能求助於那些摸到水深水淺的那些c++大神們。
之後摸著他(她)們的大腿,然後就說把源代碼的思路原形給我!

C. 求一個簡單的透明加密源代碼

事本沒改過一個代碼(但要把代碼嵌入,所以變大了)

可以象普通記事本那樣使用,但儲存出來的文件會自動加密.

那麼即使別人 走了你的文件,也無法打開看到正確的內容.

如果配合機器碼加密的話,那麼就算別人把這個記事本Copy走了,也無法打開得到正確的內容.

該技術同樣可以應用在任何軟體比如 OFFICE 系列上.

這里下載測試的 Notepad.rar

核心代碼如下,其中用到我寫的 Hook 控制項系列和加密方案:

unit MainProc;

interface

uses
Windows, Classes,
HookCoreUnit, EncrypFileUnit;

procere Start;
procere Stop;

implementation

const
ReadFileAddr = $1005244;
ReadFileAddrRts = ReadFileAddr + SizeOf(HookCodeEx);

WriteFileAddr = $1004C2A;
WriteFileAddrRts = WriteFileAddr + SizeOf(HookCodeEx);

var
ReadFileHooker, WriteFileHooker: THookerCoreEx;
MemList: TList;
EF: TEncryptFile;

function EncryptBuffer(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWORD;
var lpNumberOfBytesWritten: DWORD; lpOverlapped: POverlapped): BOOL; stdcall;
var
Data: PChar;
tmp: string;
Size: DWORD;
begin
Data:= @Buffer;

//加密
tmp:= EF.EncryptBuffer(Data, nNumberOfBytesToWrite);
Size:= Length(tmp);

Result:= WriteFile(hFile, tmp[1], Size, lpNumberOfBytesWritten, lpOverlapped);
end;

function DecryptBuffer(hFileMappingObject: THandle; dwDesiredAccess: DWORD;
dwFileOffsetHigh, dwFileOffsetLow: DWORD; dwNumberOfBytesToMap: DWORD): Pointer; stdcall;
var
MemAddr: Pointer;
tmp: string;
Size: DWORD;
begin
Result:= MapViewOfFile(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap);

//解密
tmp:= EF.DecryptBuffer(Result, dwNumberOfBytesToMap);
Size:= Length(tmp);

//如果解密有效
if Size <> 0 then
begin
//分配內存
MemAddr:= VirtualAlloc(nil, Size, MEM_COMMIT, PAGE_READWRITE);
CopyMemory(MemAddr, @tmp[1], Size);
Result:= MemAddr;

//加入內存表
MemList.Add(Result);
end; //解密不了按原內容打開
end;

procere ProcessReadFile;
asm
//解密
call DecryptBuffer

//返回
push ReadFileAddrRts
end;

procere ProcessWriteFile;
asm
//加密
call EncryptBuffer;

//返回
push WriteFileAddrRts
end;

//需要控制項的請聯系 [email protected](msn), 非商用勿擾

procere Start;
begin
{$I .\K_SDK\VM_Start.inc}
EF:= TEncryptFile.Create(nil);
EF.Enable_Encryption:= True;
EF.E_PGM:= True;
EF.FileHead:= 'NotepadEx';

MemList:= TList.Create;

ReadFileHooker:= THookerCoreEx.Create;
ReadFileHooker.HookType:= CHT_JMP;

ReadFileHooker.Instruction:= PHookCodeEx(ReadFileAddr);
ReadFileHooker.Event:= DWORD(@ProcessReadFile);

WriteFileHooker:= THookerCoreEx.Create;
WriteFileHooker.HookType:= CHT_JMP;

WriteFileHooker.Instruction:= PHookCodeEx(WriteFileAddr);
WriteFileHooker.Event:= DWORD(@ProcessWriteFile);

ReadFileHooker.Hook:= True;
WriteFileHooker.Hook:= True;
{$I .\K_SDK\VM_End.inc}
end;

procere Stop;
var
i: Integer;
begin
{$I .\K_SDK\VM_Start.inc}
WriteFileHooker.Hook:= False;
ReadFileHooker.Hook:= False;

WriteFileHooker.Free;
ReadFileHooker.Free;

//釋放內存
for i:= 0 to MemList.Count - 1 do
VirtualFree(MemList[i], 0, MEM_RELEASE);
MemList.Free;

EF.Free;
{$I .\K_SDK\VM_End.inc}
end;

end.

D. 代碼加密怎麼實現

你是想利用什麼加密,加密方法有很多.

E. VB.net實現簡單的加密解密--->該怎麼寫代碼

什麼~~這也叫加密啊,那我教你一招超簡單的"加密"方法
一個textbox1(輸入文本的) button1(名為加密) button2(名為解密)
button1的單擊事件 TextBox1.Font = New System.Drawing.Font("Symbol", CType(9, Byte))
button2的單擊事件 TextBox1.Font = New System.Drawing.Font("宋體", CType(9, Byte))
如果你要有密碼的,你可以dim一個變數用來存儲textbox2的值然後用來判斷密碼是否輸入正確

F. #試一試#  編寫程序實現簡單的字元串加密

代碼和運行情況如下:

G. 加密演算法實現代碼

這個是界面效果,我不是用C++寫的,是用C#寫的可以參考下:

實現的代碼如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Collections;

usingSystem.IO;

usingSystem.Security.Cryptography;

usingSystem.Security;

namespaceKey

{

publicpartialclassfrmKey:Form

{

privatestringkey;//默認密鑰"yupengcheng"

privatebyte[]sKey;

privatebyte[]sIV;

publicfrmKey()

{

InitializeComponent();

}

privatevoidForm1_Load(objectsender,EventArgse)

{

button4.Enabled=false;

}

///<summary>

///選擇輸入路徑

///</summary>

privatevoidbutton1_Click(objectsender,EventArgse)

{

//openFileDialog1.Filter="所有文件(*.*)|*.*";

openFileDialog1.ShowDialog();

stringfilename=openFileDialog1.FileName;

inti=filename.LastIndexOf(".");

if(i!=-1)

{

stringfiletype=filename.Substring(filename.LastIndexOf("."));

if(this.radioButton1.Checked)

{

filename=filename.Replace("(解密文件)","");

textBox2.Text=filename.Substring(0,filename.LastIndexOf("."))+"(加密文件)"+filetype;

}

else

{

filename=filename.Replace("(加密文件)","");

textBox2.Text=filename.Substring(0,filename.LastIndexOf("."))+"(解密文件)"+filetype;

}

}

if(filename!="")

{

textBox1.Text=openFileDialog1.FileName;

}

}

///<summary>

///選擇輸出路徑

///</summary>

privatevoidbutton4_Click(objectsender,EventArgse)

{

this.saveFileDialog1.ShowDialog();

if(saveFileDialog1.FileName!="")

{

this.textBox2.Text=saveFileDialog1.FileName;

}

}

///<summary>

///加密radioButton

///</summary>

privatevoidradioButton1_CheckedChanged(objectsender,EventArgse)

{

button3.Text="開始加密";

}

///<summary>

///解密radioButton

///</summary>

privatevoidradioButton2_CheckedChanged(objectsender,EventArgse)

{

button3.Text="開始解密";

}

///<summary>

///明密/暗密

///</summary>

privatevoidbutton2_Click(objectsender,EventArgse)

{

if(button2.Text=="明密")

{

textBox3.PasswordChar=Convert.ToChar(0);

button2.Text="暗密";

}

else

{

textBox3.PasswordChar=char.Parse("*");

button2.Text="明密";

}

}

///<summary>

///開始加密/開始解密

///</summary>

privatevoidbutton3_Click(objectsender,EventArgse)

{

if(this.textBox1.Text==""||this.textBox2.Text=="")

{

MessageBox.Show("文件路徑不能為空!","警告提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);

return;

}

if(textBox3.Text!="yupengcheng")

{

MessageBox.Show("輸入的密碼不正確,請重新輸入!","錯誤提示",MessageBoxButtons.OK,MessageBoxIcon.Error);

textBox3.Text="";

return;

}

else

{

key="yupengcheng";

if(button3.Text=="開始加密")

{

statusBar1.Visible=true;

statusBar1.Text="正在加密文件,請等待.....";

if(EncryptFile(this.textBox1.Text,this.textBox2.Text,textBox3.Text))

{

statusBar1.Text="加密完成。";

MessageBox.Show("文件加密成功!","成功提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

}

statusBar1.Visible=false;

}

else

{

statusBar1.Visible=true;

statusBar1.Text="正在解密文件,請等待.....";

if(DecryptFile(this.textBox1.Text,this.textBox2.Text,textBox3.Text))

{

statusBar1.Text="解密完成。";

MessageBox.Show("文件解密成功!","成功提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

}

statusBar1.Visible=false;

}

}

}

///<summary>

///取消

///</summary>

privatevoidbutton5_Click(objectsender,EventArgse)

{

Application.Exit();

}

///<summary>

///加密方法

///</summary>

///<paramname="filePath">加密輸入路徑</param>

///<paramname="savePath">加密輸出路徑</param>

///<paramname="keyStr">密匙</param>

///<returns></returns>

publicboolEncryptFile(stringfilePath,stringsavePath,stringkeyStr)

{

DESCryptoServiceProviderdes=newDESCryptoServiceProvider();

if(keyStr=="")

keyStr=key;

try

{

FileStreamfs=File.OpenRead(filePath);

byte[]inputByteArray=newbyte[fs.Length];

fs.Read(inputByteArray,0,(int)fs.Length);

fs.Close();

byte[]keyByteArray=Encoding.Default.GetBytes(keyStr);

SHA1ha=newSHA1Managed();

byte[]hb=ha.ComputeHash(keyByteArray);

sKey=newbyte[8];

sIV=newbyte[8];

for(inti=0;i<8;i++)

sKey[i]=hb[i];

for(inti=8;i<16;i++)

sIV[i-8]=hb[i];

des.Key=sKey;

des.IV=sIV;

MemoryStreamms=newMemoryStream();

CryptoStreamcs=newCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write);

cs.Write(inputByteArray,0,inputByteArray.Length);

cs.FlushFinalBlock();

fs=File.OpenWrite(savePath);

foreach(bytebinms.ToArray())

{

fs.WriteByte(b);

}

fs.Close();

cs.Close();

ms.Close();

returntrue;

}

catch

{

MessageBox.Show("找不到指定的文件,請重新輸入!","警告提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);

returnfalse;

}

}

///<summary>

///解密方法

///</summary>

///<paramname="filePath">解密輸入路徑</param>

///<paramname="savePath">解密輸出路徑</param>

///<paramname="keyStr">密匙</param>

///<returns></returns>

publicboolDecryptFile(stringfilePath,stringsavePath,stringkeyStr)

{

DESCryptoServiceProviderdes=newDESCryptoServiceProvider();

if(keyStr=="")

keyStr=key;

try

{

FileStreamfs=File.OpenRead(filePath);

byte[]inputByteArray=newbyte[fs.Length];

fs.Read(inputByteArray,0,(int)fs.Length);

fs.Close();

byte[]keyByteArray=Encoding.Default.GetBytes(keyStr);

SHA1ha=newSHA1Managed();

byte[]hb=ha.ComputeHash(keyByteArray);

sKey=newbyte[8];

sIV=newbyte[8];

for(inti=0;i<8;i++)

sKey[i]=hb[i];

for(inti=8;i<16;i++)

sIV[i-8]=hb[i];

des.Key=sKey;

des.IV=sIV;

MemoryStreamms=newMemoryStream();

CryptoStreamcs=newCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write);

cs.Write(inputByteArray,0,inputByteArray.Length);

cs.FlushFinalBlock();

fs=File.OpenWrite(savePath);

foreach(bytebinms.ToArray())

{

fs.WriteByte(b);

}

fs.Close();

cs.Close();

ms.Close();

returntrue;

}

catch

{

MessageBox.Show("找不到指定的文件,請重新輸入!","警告提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);

returnfalse;

}

}

privatevoidtextBox1_TextChanged(objectsender,EventArgse)

{

if(textBox1.Text==""||textBox1.Text==null)

{

button4.Enabled=false;

}

else

{

button4.Enabled=true;

}

}

}

}

H. 我是大一學生,剛學c語言,請問怎麼用代碼實現給文件保密。簡單的加密。註:我們是在linux環境下編程。

調用 zip 壓縮加密碼。絕對取巧但有效!
不過如果是 Linux 下面,你有很多函數庫可以找。

其實加密隨便啦,只要讓別人不能讀取出來就行了。可以說用 base64 轉碼一下都有加密效果。加密演算法有很多的,只要別用不可逆就行了。最簡單的來說,用密碼異或一下就算入門加密技術了。

閱讀全文

與簡單加密的代碼實現相關的資料

熱點內容
php判斷是否當天 瀏覽:522
驗證矩陣能否作為加密矩陣 瀏覽:772
cmd注冊表命令 瀏覽:290
kmp演算法中next數組的值怎麼求 瀏覽:992
怎麼在伺服器電腦拼ip 瀏覽:737
萬能壓縮試驗機操作規程 瀏覽:888
蘋果app怎麼收不到趣推了 瀏覽:855
單片機檢測報警 瀏覽:894
刀片式伺服器怎麼做系統 瀏覽:946
51單片機實例100 瀏覽:456
安卓怎麼進入abd調試 瀏覽:584
伺服器怎麼安裝兩個tomcat 瀏覽:696
雲伺服器數量安全嗎 瀏覽:114
程序員謎語 瀏覽:525
央行下了死命令 瀏覽:687
電腦的文件夾怎麼管理 瀏覽:83
遺傳演算法vb 瀏覽:40
主機做伺服器什麼配置好 瀏覽:614
python在excel模板生成數據 瀏覽:49
數位分離並求和python 瀏覽:41