i can't seem to get my program to save the Set.savv file and encrypt it and decrypt it when user logs back on to there virtual file on a CD and writing it to the disk its self and closing the session
8 2057 Rabbit 12,516
Recognized Expert Moderator MVP
We would need to see the code you're using.
okay let me copy it down for you
- private void EncryptFile(string inputFile, string outputFile)
-
{
-
-
try
-
{
-
string password = "H#GH!QK&"; // Your Key Here
-
UnicodeEncoding UE = new UnicodeEncoding();
-
byte[] key = UE.GetBytes(password);
-
-
string cryptFile = outputFile;
-
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
-
-
RijndaelManaged RMCrypto = new RijndaelManaged();
-
-
CryptoStream cs = new CryptoStream(fsCrypt,
-
RMCrypto.CreateEncryptor(key, key),
-
CryptoStreamMode.Write);
-
-
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
-
int data;
-
while ((data = fsIn.ReadByte()) != -1)
-
cs.WriteByte((byte)data);
-
-
-
fsIn.Close();
-
cs.Close();
-
fsCrypt.Close();
-
}
-
catch
-
{
-
-
}
-
}
-
///<summary>
-
/// Steve Lydford - 12/05/2008.
-
///
-
/// Decrypts a file using Rijndael algorithm.
-
///</summary>
-
///<param name="inputFile"></param>
-
///<param name="outputFile"></param>
-
private void DecryptFile(string inputFile, string outputFile)
-
{
-
-
{
-
string password = "H#GH!QK&"; // Your Key Here
-
-
UnicodeEncoding UE = new UnicodeEncoding();
-
byte[] key = UE.GetBytes(password);
-
-
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
-
-
RijndaelManaged RMCrypto = new RijndaelManaged();
-
-
CryptoStream cs = new CryptoStream(fsCrypt,
-
RMCrypto.CreateDecryptor(key, key),
-
CryptoStreamMode.Read);
-
-
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
-
-
int data;
-
while ((data = cs.ReadByte()) != -1)
-
fsOut.WriteByte((byte)data);
-
-
fsOut.Close();
-
cs.Close();
-
fsCrypt.Close();
-
-
}
-
}
-
}
-
}
-
-
-
- private void Login(object sender, EventArgs e)
-
{
-
string location = "Tri//Accounts//" + textBox1.Text + "//" + "Set.sav";
-
string pingGPS="Tri//Accounts//"+textBox1.Text+"//"+"Set.savv";
-
if (Directory.Exists("Tri"))
-
{
-
if (File.Exists("Tri//Accounts//" + textBox1.Text+"//"+pingGPS)&File.Exists(location))
-
{
-
DecryptFile(pingGPS, location);
-
-
StreamReader read = new StreamReader(pingGPS);
-
var reads = read.ReadLine();
-
if (reads == textBox2.Text)
-
{
-
}
-
else
-
{
-
MessageBox.Show("wrong password please try again");
-
}
-
-
}
-
else
-
{
-
MessageBox.Show(pingGPS+"........."+location+"....."+"Does not exist");
-
}
-
-
}
-
else
-
{
-
MessageBox.Show("Can't seem to find[" + textBox1.Text + "]");
-
-
}
-
-
-
-
-
}
-
-
-
-
private void timer1_Tick(object sender, EventArgs e)
-
{
-
-
timer1.Interval = 100;
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
-
string all = TriAccount + "//" + "Set.sav";
-
string all2 = TriAccount + "//" + "Set.savv";
-
//creating the account and saving it and looking for existing
-
-
-
toolStripProgressBar1.Increment(+1);
-
if (toolStripProgressBar1.Value == 1)
-
{
-
label1.Text = "Generating Key";
-
//sSecretKey = safe.GennerateKey();
-
}
-
if (toolStripProgressBar1.Value == 5)
-
{
-
label1.Text = "Creating account";
-
Properties.Settings.Default.Folder = all;
-
Properties.Settings.Default.Username = all2;
-
Properties.Settings.Default.Save();
-
Directory.CreateDirectory(TriAccount);
-
-
}
-
if (toolStripProgressBar1.Value == 10)
-
{
-
Main();
-
label1.Text = "Writing personal use data";
-
StreamWriter write = new StreamWriter(all);
-
write.WriteLine(textBox2.Text);
-
write.Flush();
-
write.Close();
-
-
}
-
if (toolStripProgressBar1.Value == 15)
-
{
-
-
-
/* FileInfo fileinfo = new FileInfo(TriAccount);
-
FileSecurity accesscontrol = fileinfo.GetAccessControl();
-
accesscontrol.AddAccessRule(new FileSystemAccessRule(TriAccount, FileSystemRights.FullControl, AccessControlType.Allow));
-
fileinfo.SetAccessControl(accesscontrol); */
-
}
-
-
if (toolStripProgressBar1.Value == 20)
-
{
-
Main();
-
label1.Text = "Applying key";
-
GCHandle gch = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned);
-
EncryptFile(TriAccount, all);
-
//safe.EncrytFile(TriAccount, all, sSecretKey);
-
-
}
-
stat.Text = toolStripProgressBar1.ToString();
-
if (toolStripProgressBar1.Value == 100)
-
{
-
timer1.Stop();
-
MessageBox.Show("Account Created,TriBot needs to Restart");
-
Application.Restart();
-
}
-
}
-
-
-
-
-
private void button3_Click(object sender, EventArgs e)
-
{
-
Main();
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
-
if (Directory.Exists(TriAccount))
-
{
-
MessageBox.Show("account exists please provide the password");
-
}
-
else
-
{
-
MessageBox.Show("This may take up to a few mintues", "Creating Account");
-
timer1.Start();
-
}
-
}
-
public void Main()
-
{
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
string triaccountkey = TriAccount + "//" + "Set.savv";
-
string keydone = TriAccount + "//" + "Set.sav";
-
-
try
-
{
-
string fileName = keydone ;
-
-
Console.WriteLine("Adding access control entry for "
-
+ fileName);
-
-
// Add the access control entry to the file.
-
AddFileSecurity(fileName, TriAccount,
-
FileSystemRights.FullControl, AccessControlType.Allow);
-
-
Console.WriteLine("Removing access control entry from "
-
+ fileName);
-
-
// Remove the access control entry from the file.
-
RemoveFileSecurity(fileName, TriAccount,
-
FileSystemRights.ReadData, AccessControlType.Allow);
-
-
Console.WriteLine("Done.");
-
}
-
catch (Exception e)
-
{
-
Console.WriteLine(e);
-
}
-
}
-
-
// Adds an ACL entry on the specified file for the specified account.
-
public static void AddFileSecurity(string fileName, string account,
-
FileSystemRights rights, AccessControlType controlType)
-
{
-
-
-
// Get a FileSecurity object that represents the
-
// current security settings.
-
FileSecurity fSecurity = File.GetAccessControl(fileName);
-
-
// Add the FileSystemAccessRule to the security settings.
-
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
-
rights, controlType));
-
-
// Set the new access settings.
-
File.SetAccessControl(fileName, fSecurity);
-
-
}
-
-
// Removes an ACL entry on the specified file for the specified account.
-
public static void RemoveFileSecurity(string fileName, string account,
-
FileSystemRights rights, AccessControlType controlType)
-
{
-
-
// Get a FileSecurity object that represents the
-
// current security settings.
-
FileSecurity fSecurity = File.GetAccessControl(fileName);
-
-
// Remove the FileSystemAccessRule from the security settings.
-
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
-
rights, controlType));
-
-
// Set the new access settings.
-
File.SetAccessControl(fileName, fSecurity);
-
-
}
-
-
}
-
}
- ;
-
using System.Security;
-
using System.Security.Cryptography;
-
using System.Runtime.InteropServices;
-
using System.Security.AccessControl;
-
-
namespace TriLockerBot
-
{
-
-
-
public partial class Form1 : Form
-
{
-
-
Safe safe = new Safe();
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
string sSecretKey;
-
-
private void EncryptFile(string inputFile, string outputFile)
-
{
-
-
try
-
{
-
string password = "H@JPK09"; // Your Key Here
-
UnicodeEncoding UE = new UnicodeEncoding();
-
byte[] key = UE.GetBytes(password);
-
-
string cryptFile = outputFile;
-
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
-
-
RijndaelManaged RMCrypto = new RijndaelManaged();
-
-
CryptoStream cs = new CryptoStream(fsCrypt,
-
RMCrypto.CreateEncryptor(key, key),
-
CryptoStreamMode.Write);
-
-
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
-
int data;
-
while ((data = fsIn.ReadByte()) != -1)
-
cs.WriteByte((byte)data);
-
-
-
fsIn.Close();
-
cs.Close();
-
fsCrypt.Close();
-
}
-
catch
-
{
-
-
}
-
}
-
///<summary>
-
/// Steve Lydford - 12/05/2008.
-
///
-
/// Decrypts a file using Rijndael algorithm.
-
///</summary>
-
///<param name="inputFile"></param>
-
///<param name="outputFile"></param>
-
private void DecryptFile(string inputFile, string outputFile)
-
{
-
-
{
-
string password = "H@JPK09"; // Your Key Here
-
-
UnicodeEncoding UE = new UnicodeEncoding();
-
byte[] key = UE.GetBytes(password);
-
if (File.Exists("Tri//Account//" + textBox1.Text + "//" + "Set.savv"))
-
{
-
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
-
-
RijndaelManaged RMCrypto = new RijndaelManaged();
-
-
CryptoStream cs = new CryptoStream(fsCrypt,
-
RMCrypto.CreateDecryptor(key, key),
-
CryptoStreamMode.Read);
-
-
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
-
-
int data;
-
while ((data = cs.ReadByte()) != -1)
-
fsOut.WriteByte((byte)data);
-
-
fsOut.Close();
-
cs.Close();
-
fsCrypt.Close();
-
}
-
else
-
{
-
MessageBox.Show("Error");
-
}
-
-
}
-
}
-
-
-
-
-
private void Form1_Load(object sender, EventArgs e)
-
{
-
-
vision.Text = "Ver:" + Application.ProductVersion;
-
}
-
-
private void Login(object sender, EventArgs e)
-
{
-
string location = "Tri//Accounts//" + textBox1.Text + "//" + "Set.sav";
-
string pingGPS="Tri//Accounts//"+textBox1.Text+"//"+"Set.savv";
-
if (Directory.Exists("Tri"))
-
{
-
if (File.Exists("Tri//Accounts//" + textBox1.Text+"//"+pingGPS)&File.Exists(location))
-
{
-
DecryptFile(pingGPS, location);
-
-
StreamReader read = new StreamReader(pingGPS);
-
var reads = read.ReadLine();
-
if (reads == textBox2.Text)
-
{
-
}
-
else
-
{
-
MessageBox.Show("wrong password please try again");
-
}
-
-
}
-
else
-
{
-
MessageBox.Show(pingGPS+"........."+location+"....."+"Does not exist");
-
}
-
-
}
-
else
-
{
-
MessageBox.Show("Can't seem to find[" + textBox1.Text + "]");
-
-
}
-
-
-
-
-
}
-
-
-
-
private void timer1_Tick(object sender, EventArgs e)
-
{
-
-
timer1.Interval = 100;
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
-
string all = TriAccount + "//" + "Set.sav";
-
string all2 = TriAccount + "//" + "Set.savv";
-
//creating the account and saving it and looking for existing
-
-
-
toolStripProgressBar1.Increment(+1);
-
if (toolStripProgressBar1.Value == 1)
-
{
-
label1.Text = "Generating Key";
-
//sSecretKey = safe.GennerateKey();
-
}
-
if (toolStripProgressBar1.Value == 5)
-
{
-
label1.Text = "Creating account";
-
Properties.Settings.Default.Folder = all;
-
Properties.Settings.Default.Username = all2;
-
Properties.Settings.Default.Save();
-
Directory.CreateDirectory(TriAccount);
-
-
}
-
if (toolStripProgressBar1.Value == 10)
-
{
-
Main();
-
label1.Text = "Writing personal use data";
-
StreamWriter write = new StreamWriter(all);
-
write.WriteLine(textBox2.Text);
-
write.Flush();
-
write.Close();
-
-
}
-
if (toolStripProgressBar1.Value == 15)
-
{
-
-
-
/* FileInfo fileinfo = new FileInfo(TriAccount);
-
FileSecurity accesscontrol = fileinfo.GetAccessControl();
-
accesscontrol.AddAccessRule(new FileSystemAccessRule(TriAccount, FileSystemRights.FullControl, AccessControlType.Allow));
-
fileinfo.SetAccessControl(accesscontrol); */
-
}
-
-
if (toolStripProgressBar1.Value == 20)
-
{
-
Main();
-
label1.Text = "Applying key";
-
GCHandle gch = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned);
-
EncryptFile(TriAccount, all);
-
//safe.EncrytFile(TriAccount, all, sSecretKey);
-
-
}
-
stat.Text = toolStripProgressBar1.ToString();
-
if (toolStripProgressBar1.Value == 100)
-
{
-
timer1.Stop();
-
MessageBox.Show("Account Created,TriBot needs to Restart");
-
Application.Restart();
-
}
-
}
-
-
-
-
-
private void Register(object sender, EventArgs e)
-
{
-
Main();
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
-
if (Directory.Exists(TriAccount))
-
{
-
MessageBox.Show("account exists please provide the password");
-
}
-
else
-
{
-
MessageBox.Show("This may take up to a few mintues", "Creating Account");
-
timer1.Start();
-
}
-
}
-
public void Main()
-
{
-
string TriAccount = "Tri//Accounts//" + textBox1.Text;
-
string triaccountkey = TriAccount + "//" + "Set.savv";
-
string keydone = TriAccount + "//" + "Set.sav";
-
-
try
-
{
-
string fileName = keydone ;
-
-
Console.WriteLine("Adding access control entry for "
-
+ fileName);
-
-
// Add the access control entry to the file.
-
AddFileSecurity(fileName, TriAccount,
-
FileSystemRights.FullControl, AccessControlType.Allow);
-
-
Console.WriteLine("Removing access control entry from "
-
+ fileName);
-
-
// Remove the access control entry from the file.
-
RemoveFileSecurity(fileName, TriAccount,
-
FileSystemRights.ReadData, AccessControlType.Allow);
-
-
Console.WriteLine("Done.");
-
}
-
catch (Exception e)
-
{
-
Console.WriteLine(e);
-
}
-
}
-
-
// Adds an ACL entry on the specified file for the specified account.
-
public static void AddFileSecurity(string fileName, string account,
-
FileSystemRights rights, AccessControlType controlType)
-
{
-
-
-
// Get a FileSecurity object that represents the
-
// current security settings.
-
FileSecurity fSecurity = File.GetAccessControl(fileName);
-
-
// Add the FileSystemAccessRule to the security settings.
-
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
-
rights, controlType));
-
-
// Set the new access settings.
-
File.SetAccessControl(fileName, fSecurity);
-
-
}
-
-
// Removes an ACL entry on the specified file for the specified account.
-
public static void RemoveFileSecurity(string fileName, string account,
-
FileSystemRights rights, AccessControlType controlType)
-
{
-
-
// Get a FileSecurity object that represents the
-
// current security settings.
-
FileSecurity fSecurity = File.GetAccessControl(fileName);
-
-
// Remove the FileSystemAccessRule from the security settings.
-
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
-
rights, controlType));
-
-
// Set the new access settings.
-
File.SetAccessControl(fileName, fSecurity);
-
-
}
-
-
}
-
}
-
-
-
-
-
Rabbit 12,516
Recognized Expert Moderator MVP
Yeah... I'm not about to read 500 lines of code.
Are you getting errors? What are the errors? Which lines cause the errors?
Are you not getting errors but it's not behaving in the way you expect? Which lines of code is executing incorrectly? What behavior is resulting? What is supposed to happen instead?
no im not getting errors. it runs fine but it wont create the encryption file and save the password from the textBox2.text and encrypt the password and then when the user types the same password in again it doesn't recognize it and cant decrypt. and I created a fail catch point to recreate the whole thing but it doesn't want to work. and I've tried everything
Rabbit 12,516
Recognized Expert Moderator MVP
Like I said earlier, I'm not trying to read 500 lines of code to find the one you're talking about. Please tell me which block of code it is and which line number you're referring to.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Lou |
last post by:
Please can someone put me out my misery!
Im trying to find a multiple user/password protection script that will
redirect the specific user to a specific directory.
At the moment I have set up htaccess which is fine but can only
protect one directory unless I put htaccess on each directory which I
think is a bit long winded, but is there any other way I can do this
with using only one password script?
Any info would be greatly...
|
by: Tim Daneliuk |
last post by:
OK, I've Googled for this and cannot seem to quite find what I need.
So, I turn to the Gentle Geniuses here for help. Here is what I
need to do from within a script:
Given a username and a password (plain text):
1) Validate that the password is correct for that user *without actually logging in*.
2) If the password is valid, return a list of all the groups the user belongs to.
Otherwise, return some error string.
|
by: Bright |
last post by:
Dear All
I'm after a multi-User password database so that I can centrally store
system passwords and give granular access to individuals based on
their own unique authentication (possibly a securID token).
I've been keeping a watchful eye for such a system but to no avail
..... has anybody come across such a system? ... I'll be most grateful
top hear about such a system!
|
by: NWx |
last post by:
Hi,
I'm an old developer, but didn't used SQL Server or MSDE to much before.
I have NetSDK instance of MSDE installed on my PC by Net Framework SDK.
All quickstart samples access it using trusted connection.
However, I want to access it using user / password, but I have no idea what
is default username / password to use.
Any help is appreciated.
|
by: Yannick Béot |
last post by:
Hi,
I'm trying to make an application that allow a user, through a web form
to change its password
On a click event, here is the code
DirectoryEntry usr = new DirectoryEntry(
theUserDN,
user,
| |
by: Daniel Walzenbach |
last post by:
Hello,
I want to create a Word XML file based on the input users make in a VB.NET application. I imagine creating a template in Word and saving it as a XML file. I then want to fill the template (in my application) based on the user input. When the document gets opened there should be fields users can change but others should be prevented from beeing changed (I know that an "open" file format like XML can always be modified to allow...
|
by: webrod |
last post by:
Hi all,
how can I check a user/password in a LDAP ?
I don't want to connect with this user, I would like to connect to LDAP
with a ADMIN_LOG/ADMIN_PWD, then do a query to find the user and check
the password.
The thing is I can't access the password attribute to compare with the
user's password provided.
|
by: Torben Laursen |
last post by:
I have made a asp.net 2.0 homepage with a number of users.
My problem is that I cannot remember what password I gave each of them.
How to I retrive a password that I gave a user?
Thanks Torben
|
by: geoharish |
last post by:
Dear All,
I started using Python just a few days back and there was a requirement of an assigned project to change the user Password through script without user interaction. I could write the following peace of code, which uses Pexpect for the same. The mentioned Poc may certainly help others, incase they need some requirement like this.
import pexpect, sys
if len(sys.argv) != 3:
print "Usage: "+sys.argv+" user new_password."
...
|
by: wolfjmt |
last post by:
Hi all
I am new to Linux, I have worked on it a little before (on Redhat 8 ), but still consider myself a novas and open SUSE is completely new to me.
I was told that there are setting that can be applied to the SUSE system that will remove(delete) a specific folder on the system if a threat is defected - see example below
If the "root" user password is reset throw the single user mode (using the passwd function); will the setup (or...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |