How to get rid of the original file path instead of name in PGP encryption with ChoPGP library? - encryption

I tried PGP encrypting a file in ChoPGP library. At the end of the process it shows embedded file name along with the whole original file name path.
But I thought it will show only the filename without the whole path. Which I intend to work on and figure out a way to do so?
Doing the following:
using (ChoPGPEncryptDecrypt pgp = new ChoPGPEncryptDecrypt())
{
pgp.EncryptFile(#"\\appdevtest\c$\appstest\Transporter\test\Test.txt",
#"\\appdevtest\c$\appstest\Transporter\test\OSCTestFile_ChoPGP.gpg",
#"\\appdevtest\c$\appstest\Transporter\pgpKey\PublicKey\atorres\atorres_publicKey.asc",
true,
true);
}
which will result in:
But I would like to only extract the Test.txt in the end something
like this:

Looking at this line from the ChoPGP sources: https://github.com/Cinchoo/ChoPGP/blob/7152c7385022823013324408e84cb7e25d33c3e7/ChoPGP/ChoPGPEncryptDecrypt.cs#L221
You may find out that it uses internal function GetFileName, which ends up with this for the FileStream: return ((FileStream)stream).Name;.
And this one, according to documentation, Gets the absolute path of the file opened in the FileStream..
So you should either make fork of ChoPGP and modify this line to extract just filename, or submit a pull request to the ChoPGP. Btw, it's just a wrapper around the BouncyCastle so you may use that instead.

Related

Is there any way to use read.fortran() to read a string rather than file?

So my problem is the following, I am reading through a text file using readlines, and have to go line by line until there is a trigger, and then I have to read the following line using read.fortran().
The problem is that read.fortran() only read text files, and I need to read a line (a string). At the moment I have solved this problem with a disastrous function which writes a file and then I read the file.
read.fortran.string <- function(x_string, x_format, x_file, col.names){
# Disastrous function to be changed
if (missing(x_file)){
x_file = r'(C:\Users\your_user\Documents\tempfolder\line.txt)'
}
write(x_string,x_file)
df = read.fortran(x_file, x_format)
if (!missing(col.names)){
colnames(df) <-col.names
}
return(df)
}
I was expecting that someone will point to a different solution in which:
Do not require to hardcode a path
Do not require having to have writing permission
I believe that
read.fortran(textConnection(x_string), x_format)
will do what you want (untested!)

QMake - Erratic behaviour When using echo System Command

Using QMake, I read some boiler plate code, make modifications and write the modified code to a file.
However, I get very strange results. I have simplified the problem down to the following:
# Open boiler plate file
interfaceBoilerPlateCode = $$cat($$boilerPlateFile, blob)
# Make sure we read the right content
message("Content read: $$interfaceBoilerPlateCode")
# Write the read text into a file
output = $$system(echo $$interfaceBoilerPlateCode >> $$targetFile) # Doesnt work
output = $$system(echo "Howde" >> $$targetFile) # This works
The file being read is a plain text file containing only the string "Howde".
The contents of the file get read correctly.
However, when I try and write the contents of the file to another target file, I get no output (literally: no errors/warnings but no new file generated). However, if I use echo with just a string defined in the code itself (as in the last line of snippet above), a new file gets generated with the string "Howde" inside it.
What is going on? What am I doing wrong that the penultimate line does not generate a new file?
Use write_file. Instead of:
$$system(echo $$content >> $$file_path)
use
write_file($$file_path, $$content)

Get the real extension of a file vb.net

I would like to determine real file extension.
example :
file = "test.fakeExt"
// but the real extention is .exe // for security reason I wish to avoid using it!
How can I do that?
If you want to determine the extension you could use findmimefromdata.
It looks at the first part of the file to determine what type of file it is.
FindMimeFromData function
Sample code
The first two bytes of an .exe file are allways 'MZ'.
So you could read the binary file, and see if the first two bytes are MZ, then you know it's an .exe file...

Powershell command for IIS 7 for replacing one string with another

I have a configuration setting in web. config file as follows:
<param name="url" value="http://localhost/services.msc">
I want to write a batch file using powershell to replace value="http://localhost/services.msc"
with port number as value="http://localhost:808/services.msc"
Is it possible to replace one text with another?
There are several ways to do this. My favorite way to modify any XML file if I know the value I'm trying to modify is to cast the content as XML, find the setting right where I know it to be, to modify it, and then to set the content of the config file to what I now have in powershell. An example is below. To find the exact value I usually take the item above it and pipe it to | fl until I get exactly what I'm looking at. You can read the XML and get the info probably alot easier.
#Make sure you set the webconfigpath variable.
#Make sure you know your keyname and where to find it in the XML doc.
$webConfig = [xml](Get-Content -path $webConfigPath)
$setting = $webConfig.configuration.appSettings.add | ?{$_.key -eq "KeyName"}
$setting.Value = "NewValue"
$webConfig.save($webConfigPath)
This may be something that can be changed with the Set-WebConfigurationProperty cmdlet, but I'm not sure and haven't used it personally.

Add file at root of zip file using DotNetZip with classic ASP

I have DotNetZip installed and running fine on a Windows 2008 server.
Using a classic ASP page, I want to bundle a bunch of comma-delimited files to a user and send it over in a zip file.
The following code works fine but it stores all the path information so the files inside the zip file are located in some ridiculous directory like C:\Inetpub\wwwroot\appname\_temp\
I'm using the following code:
Set objZip = CreateObject("Ionic.Zip.ZipFile")
sFileArray = Split(sFileArray, "|")
For iCount = 0 To UBound(sFileArray)
If sFileArray(iCount) <> "" Then
objZip.AddFile sFileArray(iCount)
End If
Next
objZip.Name = sFilePath & "test.zip"
objZip.Save()
objZip.Dispose()
Set objZip = Nothing
I see that the AddFile method allows you to specify where you want the added file to reside in the zip file if you add a second parameter. According to the documentation objZip.AddFile sFileArray(iCount), "" should put the file in the root of the zip file.
However, when I add that parameter, I get the following error:
Wrong number of arguments or invalid property assignment: 'objZip.AddFile'
Anyone have any idea what I'm doing wrong?
Thanks.
I think you are misinterperting the documentation. If the second parameter is null then the directory path of the file being added is used. If the second parameter is an empty string "" then the file is added to the root level in the zip. A quick look into the Ioniz.zip.dll shows that the single parameter override of AddFile method simply calls the the double parameter override with the second parameter set to null.
Hence your add file should look like:
objZip.AddFile sFileArray(iCount), ""
to get the result you are after.

Resources