|
Help.
Has anyone managed to get GnuPG working from C#?
I have installed the latest version of GnuPG and downloaded the wrapper GnuPGWrapper from this site.
I've created a new registry key called HomeDir in HKEY_CURRENT_USER\Software\GNU\GnuPG with a value
of "C:\Program Files\GNU\GnuPG\" the gpg.exe and keyring files are also in this location.
When I run my simple console application I get this error.
"Emmanuel.Cryptography.GnuPG.GnuPGException was unhandled
Message="gpg: keyblock resource `C:/Program Files/GNU/GnuPG\" --yes --batch --encrypt --armor --recipient crypto@turpin-distribution.com --default-key crypto@turpin-distribution.com --passphrase-fd 0 --no-verbose \\secring.gpg': file open error\r\ngpg: keyblock resource `C:/Program Files/GNU/GnuPG\" --yes --batch --encrypt --armor --recipient crypto@turpin-distribution.com --default-key crypto@turpin-distribution.com --passphrase-fd 0 --no-verbose \\pubring.gpg': file open error\r\ngpg: no valid OpenPGP data found.\r\ngpg: processing message failed: eof\r\n"
"
Has anyone got a working example of this that they would be kind enough to post as I've now pulled all my hair out
My console application looks like this..
using System;
using Emmanuel.Cryptography.GnuPG;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
string inputText;
string outputText;
GnuPGWrapper gpg = new GnuPGWrapper();
gpg.command = Commands.Encrypt;
gpg.homedirectory = @"C:\Program Files\GNU\GnuPG\";
gpg.passphrase = "fred";
gpg.originator = "crypto@turpin-distribution.com";
gpg.recipient = "crypto@turpin-distribution.com";
inputText = "Hello World";
gpg.ExecuteCommand(inputText, out outputText);
Console.WriteLine("Input = {0}, Output = {1}", inputText,outputText);
}
}
}
|
|
|
|
|
Seems like the main error is the following:
davidmgray_de wrote: file open error
davidmgray_de wrote: no valid OpenPGP data found
Have you tried the vendors website?? They might have better support on this product or have documentation available on how to use this.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Good morning.
I am trying to remove any special characters in a string I pass.
I came across this code:
using System.Text.RegularExpressions;
string = Regex.Replace(string, @"[^\w\.]", "");
It appear to work very well, except it doesn't "filter" out the underscore (_)character for some reason.
I was hoping someone could help me better understand what the
@"[^\w\.]", does and how I can add or remove something to filter out the underscore.
Thank you, WHEELS
|
|
|
|
|
Try @"[^_\w\.]"
The regexp is actually just the this [^\w\.] - this is a character class (because its in []). The ^ immediately after [ says exclude any chars in the class. The \w says any char that is a word char (roughly letters and digits) and the \. says period. The \ are escapes w by itself matches the letter w and . by itself matches any char.
The @ is used in C# to prevent it processing \ as an escape in a string literal - without it you would have to use "[^\\w\\.]".
There's some good stuff to be found by googling for 'regular expressions c#'
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Thank you riced.
Any idea on how to rid the string from the (_) underscore?
WHEELS
|
|
|
|
|
Did you try @"[^_\w\.]" ? Note the _ after the ^ I don't know why the underscore is staying in since AFAIK \w should only compare with letters or digits (but I've not used anything like this in C#).
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi riced.
I read your response too quickly.
I tried
string = Regex.Replace(string, @"[^_\w\.]", "");
but unfortunately it didn't do the trick.
WHEELS
|
|
|
|
|
I think its an Oops on my part the ^_ says don't replace _.
Try @"[^\w\.]|_" - i.e. non-word or _.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Hi ricer.
It worked awesome.
Thanks again.
WHEELS
|
|
|
|
|
Fatal mistake in my first reply - failed to engage brain
And the 'negative logic' got by using [^...] always confuses me.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
I cannot help you with the underscore part, but:
\w means any character in a-z, A-Z, 0-9 or _
\. means a literal full-stop as it is escaped
the ^ means Negate
put it all together and you get 'anything that is NOT a character or number, an underscore or a full-stop'.
I have had a thought about the underscore. Since \w includes the underscore, replace it with your own character class that doesn't include the underscore.
Something like @"[^[a-zA-Z0-9]\.]"
WARNING This may not work, as I have only just started on regular expressions.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you Henry. That is very helpful. Are you stating that there is no way to configure the parmeter to filter out the underscore?
WHEELS
|
|
|
|
|
If you only want letters and/or full stops try the following:
string initial = @"abc_def<>";
string replaced = Regex.Replace(initial, @"[^A-Za-z\.]", "");
MessageBox.Show(replaced);
I guess you might need to amend it to allow spaces etc but at least it gets rid of underscores.
|
|
|
|
|
No, I'm saying that I do not know how to do it. I did however modify my post with an attempt to do so. But as I say in the modification it may not work as I am new to regex myself.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
If you think you might use regular expressions in other applications, can I commend to you Expresso Regular Expression Development Tool[^]. It's free, and it's good.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you very much for that! I can see Regex being seriously usefull, but it looks so APL like that I just shudder and try to look away...
This could realy help!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I never actually used APL, although one place I worked there were some who did. One look at the keyboard was enough to put me off.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
How can I parse parenthesis block in string?
For example I have formula in string format.
((10+5)*3/(2+1))+7
I want to add stack to following order;
(10+5)
*
3
/
(2+1)
+
7
Thanks...
|
|
|
|
|
What have you tried so far? Do you have some code?
What are you asking here? If you're after somebody to write a parser for you generally you need to pay someone.
|
|
|
|
|
You could try taking a look at State of the Art Expression Evaluation[^], one of the many Expression Parsers here on CP. There are loads more on the web.
Have root round till you find one that suits your requirements, or can be easily modified to do so.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
|
Sounds like you want the Shunting-yard algorithm[^]
You may have to change the "output queue" to "output stack" but that's trivial.
|
|
|
|
|
can we create object of partial class
This code was posted by me...
|
|
|
|
|
Yes, for example, the following code works:
public partial class Class1
{
int i = 10;
public void Foo()
{
Console.WriteLine(i);
}
}
static class Program
{
static void Main()
{
Class1 cl1 = new Class1();
cl1.Foo();
}
}
|
|
|
|
|
Yes but it will create an instance of all parts of the class (if that makes sense) and not just one of the partial implementations.
|
|
|
|