如何用注册表对delphi程序加密
|
源代码网整理以下本加密方法分三部分: 源代码网整理以下 1. 根据对注册表的搜索结果判定设置对话框的内容。 源代码网整理以下 2. 若初次使用,则设新密码;若是已经设置密码,则进行验证。 源代码网整理以下 3. 一个密码变换小程序(比原来的复杂得多)。当然,如果需要修改密码的功能,只要将设置密码部分改动一下即可。 源代码网整理以下 一、程序启动时,通过搜索注册表,判断是否已有密码,来确定窗口的显示内容。不过事先应有以下的声明然后才能使用: 源代码网整理以下 在user中加入TRegistry,在var声明中加入以下几个窗体变量: 源代码网整理以下 源代码网整理以下 procedure TfrmPass.FormShow(Sender: TObject); 软件开发网 www.mscto.com
源代码网整理以下 begin 源代码网整理以下 TheReg := TRegistry.Create; 源代码网整理以下 try TheReg.RootKey := HKEY—LOCAL—MACHINE; 源代码网整理以下 KeyName := ′SOFTWAREMypassword′; 源代码网整理以下 //有该键则打开,没有则创建 软件开发网 www.mscto.com
源代码网整理以下 if TheReg.OpenKey(KeyName, True) then begin 源代码网整理以下 tempStr:=ExtractFileName(Application.ExeName); //读取密码 源代码网整理以下 ValueStr:=TheReg.ReadString(tempStr); 源代码网整理以下 //密码不为空则修改窗体为验证密码 源代码网整理以下 if ValueStr<>′′ then begin 源代码网整理以下 edit2.Visible:=false; frmPass.Caption:=′验证密码′; 软件开发网 www.mscto.com
源代码网整理以下 edit1.SetFocus; OK.Caption:=′确定′; end 源代码网整理以下 //密码为空则修改窗体为设置密码对话框 源代码网整理以下 else begin 源代码网整理以下 showmessage(′第一次使用请设置密码!′); 源代码网整理以下edit2.Visible:=true; frmPass.Caption:=′请设置新密码′; 软件开发网 www.mscto.com
源代码网整理以下 end; TheReg.CloseKey; end; 源代码网整理以下 finally TheReg.Free; end; end; 源代码网整理以下 源代码网整理以下 源代码网整理以下 //根据Edit2的显示与否判断已有密码,进行验证 源代码网整理以下 if edit2.Visible=false then begin 源代码网整理以下 if pass(edit1.text)=ValueStr then begin 源代码网整理以下 showmessage(′密码正确!′); end 源代码网整理以下 else begin 源代码网整理以下 showmessage(′密码不正确!无权操作!′); 源代码网整理以下 halt; end; end //无密码,设置新密码 源代码网整理以下 else begin 软件开发网 www.mscto.com 源代码网整理以下 if edit1.text=edit2.text then begin 源代码网整理以下 TheReg := TRegistry.Create; 源代码网整理以下 TheReg.RootKey := HKEY—LOCAL—MACHINE; 软件开发网 www.mscto.com
源代码网整理以下 KeyName := ′SOFTWAREMypassword′; 源代码网整理以下 if TheReg.OpenKey(KeyName, True) then 源代码网整理以下 TheReg.WriteString(tempStr,pass(edit1.text)); 软件开发网 www.mscto.com 源代码网整理以下 TheReg.CloseKey; end 源代码网整理以下 else begin 源代码网整理以下 showmessage(′再次键入的密码不一致,请重输!′); 源代码网整理以下edit1.text:=′′; edit2.text:=′′; 源代码网整理以下 end; end; 源代码网整理以下 源代码网整理以下 这个变换小程序在笔者看来还不算很复杂,只进行了两次变换,不过,想要破译也是得费点劲。读者还可以采用其他的数学函数进行更为复杂的变换。 源代码网整理以下 源代码网整理以下 i,j:integer; 源代码网整理以下 begin 源代码网整理以下 str:=pstr; 软件开发网 www.mscto.com
源代码网整理以下 for i:=1 to length(str) do begin 源代码网整理以下 //进行第一次变换 源代码网整理以下 j:=(i*i*i mod (i+20))+(i*i mod (i+10))+i*2+1; 软件开发网 www.mscto.com 源代码网整理以下 str1:=str1+chr(ord(str[i])+j); //第二次变换 源代码网整理以下 j:=(i*i*i mod (i+10))+(i*i mod (i+20))+i*2+1; 源代码网整理以下 str1:=str1+chr(ord(str[i])+j); end; 源代码网整理以下 pass:=str1; 软件开发网 www.mscto.com 源代码网整理以下 end; 源代码网整理以下 源代码网推荐 源代码网供稿. |
