Click here to Skip to main content
15,895,880 members
Home / Discussions / C#
   

C#

 
QuestionGetting substring from a line Pin
ipstefan8-Jan-09 21:02
ipstefan8-Jan-09 21:02 
AnswerRe: Getting substring from a line Pin
Jason C Bourne8-Jan-09 21:10
Jason C Bourne8-Jan-09 21:10 
GeneralRe: Getting substring from a line Pin
ipstefan8-Jan-09 21:23
ipstefan8-Jan-09 21:23 
GeneralRe: Getting substring from a line Pin
Kristian Sixhøj8-Jan-09 21:26
Kristian Sixhøj8-Jan-09 21:26 
GeneralRe: Getting substring from a line Pin
ipstefan8-Jan-09 21:36
ipstefan8-Jan-09 21:36 
GeneralRe: Getting substring from a line Pin
Kristian Sixhøj8-Jan-09 21:39
Kristian Sixhøj8-Jan-09 21:39 
AnswerRe: Getting substring from a line Pin
sourabhsorate9-Jan-09 22:51
sourabhsorate9-Jan-09 22:51 
QuestionHow to digital sign a string with X509 .pfx file Pin
hoanhtuan8-Jan-09 20:46
hoanhtuan8-Jan-09 20:46 
Dear all,

I am working on C# project, which need to digital sign on all data (string DataType). I have .pfx (X509) file already (contain public key + private key). Is there anyway to pass the private key + public key in .pfx file to DSA, to create digital signature ?

Below is the code in JAVA, which I think use DSA in C# may create the digital sign exactly this java code.

Many thank if you can help.

//---------------------- JAVA DIGITAL SIGN CODE ---------------------
private static void readPrivateKeyAsClassPath() {
try {
// Read key
InputStream fis = SignatureDegist.class.getResourceAsStream("/"
+ keyFile);
ObjectInputStream ois = new ObjectInputStream(fis);
priv = (PrivateKey) ois.readObject();
ois.close();

} catch (Exception e) {

}
}

/**
* @param filename
* @throws FileNotFoundException
* @throws IOException
* @throws ClassNotFoundException
*/
private static void readKeysPrivateKey(String filename)
throws FileNotFoundException, IOException, ClassNotFoundException {
if (priv == null) {
setKeyName(filename);
readPrivateKeyAsClassPath();
}
}

private static byte[] sign(InputStream reader, String sigAlg)
throws Exception {
Properties pro = new Properties();
pro.load(SignatureDegist.class.getResourceAsStream(CONFIG_KEY_FILE_LOCATION));

if (priv == null) {
readKeysPrivateKey(pro.getProperty("filename"));
}

Signature sig = Signature.getInstance(sigAlg);
sig.initSign(priv);

byte[] dataBytes = new byte[1024];
int nread = reader.read(dataBytes);
while (nread > 0) {
sig.update(dataBytes, 0, nread);
nread = reader.read(dataBytes);
}
;
return sig.sign();
}

private static byte[] sign(String datafile, String sigAlg) throws Exception {

return sign(new ByteArrayInputStream(datafile.getBytes()), sigAlg);
}

public static void main(String[] unused) throws Exception {
// Generate a key-pair

String accountIdSource = "123100003456";
String accountIdDest = "456100014123";
long value = 100;
String desc = "transfer";
String contactID = "NHK-XJ";
String typeId = "00";

StringBuffer buffer = new StringBuffer();
buffer.append(accountIdSource);
buffer.append(accountIdDest);
buffer.append(value);
buffer.append(desc);
buffer.append(contactID);
buffer.append(typeId);

byte[] degist = sign(buffer.toString(), "SHAwithDSA");
System.out.println("Signature degist :: " + degist);
System.out.println("Signature degist :: " + new String(degist));
Base64 decoder = new Base64();

System.out.println("Signature degist :: " + new String(decoder.encode(degist)));

System.out.println("Signature degist :: " + new String(decoder.encode(new String(decoder.encode(degist)).getBytes())));
Question"ANY CPU" compilation - what gives? Pin
harleydk8-Jan-09 20:30
harleydk8-Jan-09 20:30 
AnswerRe: "ANY CPU" compilation - what gives? [modified] Pin
Colin Angus Mackay8-Jan-09 22:27
Colin Angus Mackay8-Jan-09 22:27 
GeneralRe: "ANY CPU" compilation - what gives? Pin
harleydk9-Jan-09 1:02
harleydk9-Jan-09 1:02 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Guffa9-Jan-09 1:19
Guffa9-Jan-09 1:19 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Guffa9-Jan-09 1:18
Guffa9-Jan-09 1:18 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Colin Angus Mackay9-Jan-09 1:25
Colin Angus Mackay9-Jan-09 1:25 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Guffa9-Jan-09 5:51
Guffa9-Jan-09 5:51 
AnswerRe: "ANY CPU" compilation - what gives? Pin
Guffa9-Jan-09 1:17
Guffa9-Jan-09 1:17 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Colin Angus Mackay9-Jan-09 1:30
Colin Angus Mackay9-Jan-09 1:30 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Daniel Grunwald9-Jan-09 1:56
Daniel Grunwald9-Jan-09 1:56 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Luc Pattyn9-Jan-09 3:45
sitebuilderLuc Pattyn9-Jan-09 3:45 
GeneralRe: "ANY CPU" compilation - what gives? Pin
Colin Angus Mackay9-Jan-09 5:39
Colin Angus Mackay9-Jan-09 5:39 
AnswerRe: "ANY CPU" compilation - what gives? Pin
Dave Kreskowiak9-Jan-09 1:58
mveDave Kreskowiak9-Jan-09 1:58 
GeneralRe: "ANY CPU" compilation - what gives? Pin
harleydk11-Jan-09 10:51
harleydk11-Jan-09 10:51 
QuestionPlaying DVD Pin
Identity Undisclosed8-Jan-09 20:15
Identity Undisclosed8-Jan-09 20:15 
AnswerRe: Playing DVD Pin
EliottA9-Jan-09 2:34
EliottA9-Jan-09 2:34 
GeneralRe: Playing DVD Pin
Identity Undisclosed11-Jan-09 21:50
Identity Undisclosed11-Jan-09 21:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.