|
Refering to sun.com[^] JAVA is running 4.5 billion PC's worldwide - why use anything else for a keylogger-virus??
You should start with a concept. A concept does make it easier. I'm pretty sure about that!
greets
Torsten
___________________________________________________________________
I never finish anyth...
|
|
|
|
|
It's really like comparing apples and oranges but anyone will tell you to do it in C++. The advantages of C++ outweigh Java any day of the week; java is intepreted and slow. C++ is native and fast.
Yeah, the only reason I'm helping you us because of the sheer stupidity of your question, in fact it is indeed so stupid, I have absolutely no confidence in your ability to learn java, nevertheless C++.
Good luck at failing.
|
|
|
|
|
It is possible to do it in both but it all comes down to your preference.
Since you posted in Java forum you can use this http://www.steelbrothers.ch/jusb/ Learn it by yourself (no support on this one due to the nature of your application)
Just in case you want to verify input and not log the keys. This is limited to your application.
Snippet
addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
}
});
|
|
|
|
|
Hi everyone,
I planned to do a project in Digital Signature.
I just know how to Digitally Sign a Static document.
Now, I need to know, how to sign a document that has a dynamic content.
Can anyone help me to know, how to sign a dynamic content document!
I jus need the steps for how to sign a dynamic document.
Regards,
Vivek
|
|
|
|
|
I need to implement the solution for the dynamic content digital signature as in the paper below!
Just for reference.... http://www.isg.rhul.ac.uk/cjm/dcaods.pdf
|
|
|
|
|
so you have your reference doc, what have you tried?
If this is an accademic project [aka homework] the security of the signature is not too important, it is just the concept.
If this is commercial, then go out and buy a solution - it will be secure and properly tested.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Interesting project, so I believe the main issue is how to implement the aware application that replace the dynamic content from the document, the rest can be achieved easily including the security side notes.
Any one willing to suggest how to do the separation?
modified on Friday, September 4, 2009 10:46 PM
|
|
|
|
|
Ok since my last post I was thinking about how to implement (Just to learn more thats all) the digital awareness but came to a conclusion that for every application we would require to define its own awareness method which I find not practical. Luckily I remembered what we took in email security especially S/MIME the concept of envelop, therefore I thought why not do the same with this problem.
The solution is to convert the given file into a byte array text file and then digitally sign it.
The code I used is as follows (I was lazy to do the output for the data,key,sig) but its easy to do.
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.DSAPublicKey;
public class SigningDocument
{
public static void main(String[] args) throws Exception
{
InputStream in = new FileInputStream("dcaods.pdf");
int bytesRead=0;
int bytesToRead=1024;
byte[] input = new byte[bytesToRead];
while (bytesRead < bytesToRead)
{
int result = in.read(input, bytesRead, bytesToRead - bytesRead);
if (result == -1) break;
bytesRead += result;
}
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
DSAPrivateKey privateKey = (DSAPrivateKey)keypair.getPrivate();
DSAPublicKey publicKey = (DSAPublicKey)keypair.getPublic();
byte[] signature= createSignature(privateKey,input);
boolean v = verifySignature(publicKey,input,signature);
System.out.print(v);
}
public static byte[] createSignature(PrivateKey key, byte[] buffer)
{
try
{
Signature sig = Signature.getInstance(key.getAlgorithm());
sig.initSign(key);
sig.update(buffer, 0, buffer.length);
return sig.sign();
}
catch (SignatureException e) {}
catch (InvalidKeyException e) {}
catch (NoSuchAlgorithmException e) {}
return null;
}
public static boolean verifySignature(PublicKey key, byte[] buffer, byte[] signature)
{
try
{
Signature sig = Signature.getInstance(key.getAlgorithm());
sig.initVerify(key);
sig.update(buffer, 0, buffer.length);
return sig.verify(signature);
}
catch (SignatureException e) {}
catch (InvalidKeyException e) {}
catch (NoSuchAlgorithmException e) {}
return false;
}
}
What do you think guys?
|
|
|
|
|
@Nagy Vilmos
I am doing this for my learning purpose only and not commercial.
@Member 4277480,
I can understand that you are converting a given file into a text file and digitally signing it.
But, again if the file is renamed the content will become dynamic. To get the true requirement
just have a look at http://www.unirc.it/firma/en/Buccafurri_ISSA_1008.pdf[^]
So, we need to remove the dynamic contents present in it or do some manipulations.
The thing is i cannot figure out how to remove the dynamic content or how to do some manipulations to make the content static.
Thanks in advance!!!
|
|
|
|
|
1. For file name I included it with the digital signature.
2. I zipped my outputs.
3. Created a checksum.
Does this do it? About your concern of dynamic and static the only way I could think of is that each program should have a built in converter to satisfy the condition that was mentioned in your first pdf.
import java.io.*;
import java.math.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;
import java.util.*;
import java.util.zip.*;
import javax.swing.*;
public class SigningDocument_2
{
public static void main(String[] args) throws Exception
{
JFileChooser chooser = new JFileChooser();
JFrame frame = new JFrame();
chooser.showOpenDialog(frame);
File file = chooser.getSelectedFile();
frame.dispose();
String FileName = file.getPath();
InputStream in = new FileInputStream(FileName);
int bytesRead=0;
int bytesToRead=(int) new File(FileName).length();
byte[] input = new byte[bytesToRead];
while (bytesRead < bytesToRead)
{
int result = in.read(input, bytesRead, bytesToRead - bytesRead);
if (result == -1) break;
bytesRead += result;
}
byte [] FileNameToByte = FileName.getBytes();
byte [] DataToSign = new byte[input.length +FileNameToByte.length];
for (int i = 0; i < input.length; i++)
{
DataToSign[i] = input[i];
}
int k =0;
for (int i = input.length; i < DataToSign.length; i++)
{
DataToSign[i] = FileNameToByte[k];
k++;
}
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
keyGen.initialize(1024);
KeyPair keypair = keyGen.genKeyPair();
DSAPrivateKey privateKey = (DSAPrivateKey)keypair.getPrivate();
DSAPublicKey publicKey = (DSAPublicKey)keypair.getPublic();
DSAParams dsaParams = privateKey.getParams();
BigInteger p = dsaParams.getP();
BigInteger q = dsaParams.getQ();
BigInteger g = dsaParams.getG();
BigInteger y = publicKey.getY();
byte[] signature= createSignature(privateKey,DataToSign);
File output = new File("Bytes.txt");
PrintWriter out = new PrintWriter(output);
for (int i =0; i < input.length; i++)
{
out.println(input[i]);
}
out.println(FileName);
out.close();
File output2 = new File("Key.txt");
PrintWriter out2 = new PrintWriter(output2);
out2.println("DSA");
out2.println(p);
out2.println(q);
out2.println(g);
out2.println(y);
out2.close();
File output3 = new File("Signature.txt");
PrintWriter out3 = new PrintWriter(output3);
for (int i =0; i < signature.length; i++)
{
out3.println(signature[i]);
}
out3.close();
Zip("Bytes.txt","Key.txt","Signature.txt");
unZip("Result.zip","checksum.txt");
}
public static byte[] createSignature(PrivateKey key, byte[] buffer)
{
try
{
Signature sig = Signature.getInstance(key.getAlgorithm());
sig.initSign(key);
sig.update(buffer, 0, buffer.length);
return sig.sign();
}
catch (SignatureException e) {}
catch (InvalidKeyException e) {}
catch (NoSuchAlgorithmException e) {}
return null;
}
public static void Zip(String Bytes,String Key,String Signature)
{
String[] filenames = new String[]{Bytes,Key,Signature};
byte[] buf = new byte[1024];
try
{
String outFilename = "Result.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
for (int i=0; i < filenames.length; i++)
{
FileInputStream in = new FileInputStream(filenames[i]);
out.putNextEntry(new ZipEntry(filenames[i]));
int len;
while ((len = in.read(buf)) > 0)
{
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
CheckedInputStream cis = new CheckedInputStream(
new FileInputStream(outFilename), new Adler32());
byte[] tempBuf = new byte[1024];
while (cis.read(tempBuf) >= 0) {}
long checksum = cis.getChecksum().getValue();
PrintWriter checksumout = new PrintWriter(new File("checksum.txt"));
checksumout.write(checksum+"");
checksumout.close();
}
catch (IOException e) {}
}
public static void unZip(String zip,String checksumfile) throws NoSuchAlgorithmException, InvalidKeySpecException
{
try
{
ZipFile zf = new ZipFile(zip);
CheckedInputStream cis = new CheckedInputStream(
new FileInputStream(zip), new Adler32());
byte[] tempBuf = new byte[1024];
while (cis.read(tempBuf) >= 0) {}
long checksum = cis.getChecksum().getValue();
Scanner scan = new Scanner(new File(checksumfile));
long verifychecksum = scan.nextLong();
if (verifychecksum == checksum)
{
Enumeration<?> e = zf.entries();
while (e.hasMoreElements())
{
ZipEntry ze = (ZipEntry) e.nextElement();
FileOutputStream fout = new FileOutputStream(ze.getName());
InputStream in = zf.getInputStream(ze);
for (int c = in.read(); c != -1; c = in.read())
{
fout.write(c);
}
in.close();
fout.close();
}
ArrayList<String> Bytes = new ArrayList<String>();
Scanner scanBytes = new Scanner(new File("Bytes.txt"));
while(scanBytes.hasNext())
Bytes.add(scanBytes.nextLine());
ArrayList<String> Key = new ArrayList<String>();
Scanner scanKey = new Scanner(new File("Key.txt"));
while(scanKey.hasNext())
Key.add(scanKey.nextLine());
String algorithm = Key.get(0);
BigInteger p = new BigInteger(Key.get(1));
BigInteger q = new BigInteger(Key.get(2));
BigInteger g = new BigInteger(Key.get(3));
BigInteger y = new BigInteger(Key.get(4));
KeyFactory keyFactory = KeyFactory.getInstance(algorithm);
KeySpec publicKeySpec = new DSAPublicKeySpec(y, p, q, g);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
ArrayList<String> Signature = new ArrayList<String>();
Scanner scanSignature = new Scanner(new File("Signature.txt"));
while(scanSignature.hasNext())
Signature.add(scanSignature.nextLine());
byte [] sig = new byte[Signature.size()];
for (int i =0; i < sig.length;i++)
{
sig[i] = new Byte(Signature.get(i));
}
byte [] bytes = new byte[Bytes.size()];
for (int i =0; i < bytes.length-1;i++)
{
bytes[i] = new Byte(Bytes.get(i));
}
String filename = Bytes.get(Bytes.size()-1);
byte [] FileNameToByte = filename.getBytes();
byte [] DataToSign = new byte[bytes.length +FileNameToByte.length-1];
for (int i = 0; i < bytes.length-1; i++)
{
DataToSign[i] = bytes[i];
}
int k =0;
for (int i = bytes.length-1; i < DataToSign.length; i++)
{
DataToSign[i] = FileNameToByte[k];
k++;
}
boolean bool = verifySignature(publicKey,DataToSign,sig);
if(bool)
{
BuildFile(filename,bytes);
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + filename);
}
else
JOptionPane.showMessageDialog(null,"Warning", "Warning Message",JOptionPane.WARNING_MESSAGE);
}
}
catch (IOException e) {}
}
public static boolean verifySignature(PublicKey key, byte[] buffer, byte[] signature)
{
try
{
Signature sig = Signature.getInstance(key.getAlgorithm());
sig.initVerify(key);
sig.update(buffer, 0, buffer.length);
return sig.verify(signature);
}
catch (SignatureException e) {}
catch (InvalidKeyException e) {}
catch (NoSuchAlgorithmException e) {}
return false;
}
public static void BuildFile(String FileName,byte[] bytes) throws IOException
{
FileOutputStream m = new FileOutputStream(FileName);
m.write(bytes);
m.close();
}
}
modified on Saturday, September 5, 2009 10:15 PM
|
|
|
|
|
public class duplicate {
int temp, true_count;
int ar[] = { 1, 2, 3, 4, 1 };
int count;
public void find() {
for (int i = 0; i < ar.length - 1; i++) {
temp = ar[i];
for (int j = i; j <= ar.length-1 ; j++) {
if (temp == ar[j]) {
count += 1;
}
}
}
}
public static void main(String args[]) {
duplicate dup = new duplicate();
dup.find();
System.out.println("The No of duplicates is :" + dup.count);
}
}
This program is supposed to count the no. of duplicates in thearray and print the same. There is something wrong in the loop. PLs tell me what is wrong with the code.
Thanks
|
|
|
|
|
Have you tried stepping through the code? Even with pencil you will see very quickly:
for (int i = 0; i < ar.length - 1; i++)
Elements of the array are 0..4 and the length is 5. At what value for i is the loop exited?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Time to do some homework
- Computers (and i assume all being aside humans) do intent to count from 0!
- Make sure you're not finding the number itself. (for example: do not compare the first digit to itself!).
- step out of the loop if you've found what you were looking for.
greets
Torsten
I never finish anyth...
|
|
|
|
|
In other words change your for loops to
1. for (int i = 0; i < ar.length; i++)
2. for (int j = i+1; j < ar.length; j++)
Regards
|
|
|
|
|
I want that in textbox if 0 is insert than it shows an alert message. The textbox insert numbers only. How will I validate it? please help
thanx in advance.
|
|
|
|
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Validate extends JFrame
{
TextField t;
public Validate()
{
t= new TextField(10);
add(t);
t.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
if ((key == KeyEvent.VK_0))
{
JOptionPane.showMessageDialog(null,"0 Was Clicked", "Note",JOptionPane.INFORMATION_MESSAGE);
}
else
if((key == KeyEvent.VK_1)||(key == KeyEvent.VK_2)||(key == KeyEvent.VK_3)||(key == KeyEvent.VK_4)||(key == KeyEvent.VK_5)||(key == KeyEvent.VK_6||(key == KeyEvent.VK_7)||(key == KeyEvent.VK_8)||(key == KeyEvent.VK_9)))
{
return;
}
else
{
JOptionPane.showMessageDialog(null,"Invalid Input", "Note",JOptionPane.WARNING_MESSAGE);
String s = t.getText();
t.setText(s.replaceAll(e.getKeyChar()+"",""));
}
}
}
);
setTitle("Validate");
setLocationRelativeTo(null);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args)
{
new Validate();
}
}
|
|
|
|
|
Would it not be simpler to use a JFormattedTextField to ensure numeric input and an InputVerifier to check the value is not 0?
|
|
|
|
|
True there are many ways to do it.
Snippet 1: Integers
public Validate()
{
Text.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEvent e)
{
char c = e.getKeyChar();
if (!(Character.isDigit(c) ||(c == KeyEvent.VK_BACK_SPACE) ||(c == KeyEvent.VK_DELETE)))
{
getToolkit().beep();
e.consume();
}
if( c == KeyEvent.VK_0)
{
Label.setText("0 entered");
Label.setForeground(Color.red);
}
else
{
Label.setText("ok");
Label.setForeground(Color.black);
}
}
});
Snippet 2: Double
public class Validate()
{
DoubleValidate dv = new DoubleValidate();
public Validate()
{
Text.setDocument(dv);
add(Text);
}
static class DoubleValidate extends PlainDocument
{
public void insertString(int offset,String string, AttributeSet attributes)throws BadLocationException
{
if (string == null)
{
return;
}
else
{
String newValue;
int length = getLength();
if (length == 0)
{
newValue = string;
}
else
{
String currentContent = getText(0, length);
StringBuffer currentBuffer = new StringBuffer(currentContent);
currentBuffer.insert(offset, string);
newValue = currentBuffer.toString();
}
try
{
Double.parseDouble(newValue);
super.insertString(offset, string,attributes);
}
catch (NumberFormatException exception)
{
Toolkit.getDefaultToolkit().beep();
}
}
}
}
}
|
|
|
|
|
Yes, there are many ways to make something more complicated than it needs to be.
|
|
|
|
|
I m trying to Run a blackbery Application on simulator using Jdk,jre and Eclipse The project but When i run Build.xml as Run as Ant then get some building errors like
Buildfile: E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
buildAndPackageTarget:
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
clean:
[delete] Deleting directory E:\Current\BlackBerry Projects\4th\mfunds-java\preprocessed\${alias}
[delete] Deleting directory E:\Current\BlackBerry Projects\4th\mfunds-java\classes\${alias}
[echo] Target ${alias} was cleaned
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
preprocess:
[mkdir] Created dir: E:\Current\BlackBerry Projects\4th\mfunds-java\preprocessed\${alias}
[wtkpreprocess] **************************************************************
[wtkpreprocess] * Antenna 1.0.1 initialized for project "telSPACE Java" *
[wtkpreprocess] * Using Sun Wireless Toolkit 2.5 (CLDC-1.0; MIDP-2.0) *
[wtkpreprocess] **************************************************************
[wtkpreprocess] Preprocessing 40 file(s) at E:\Current\BlackBerry Projects\4th\mfunds-java\src
[echo] Pre-processed successfuly with: ${platform}, ${platformver}, ${alias}, ${alias2}
[typedef] Could not load definitions from resource net/sf/antcontrib/antlib.xml. It could not be found.
compile:
[mkdir] Created dir: E:\Current\BlackBerry Projects\4th\mfunds-java\classes\${alias}
BUILD FAILED
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:334: The following error occurred while executing this line:
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:377: Problem: failed to create task or type if
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
Total time: 18 seconds
please suggest some thing
|
|
|
|
|
Ok,
The problem lies in...
E:\Current\BlackBerry Projects\4th\mfunds-java\build\build.xml:377: Problem: failed to create task or type if
That error tells me you that...
Cause: The name is undefined.
and you should...
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
See? All that and all I did was read what your compiler shat out...
|
|
|
|
|
Please give me project in Java my platform is netbeans 5.5. or tell me some websites where i got projects. I want to try to make my project please help me.
thanx in advance.
|
|
|
|
|
You want someone to do what ? Send you a project ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I write a code for automatic ID generated. But If somebody deleted the Id for example I have three ID i.e. 001,002, 003. If somebody deleted 002 so when we add the id is generated 004 but I want the ID is generated 002. Please tell me
thanx in advance.
|
|
|
|
|
http://doc.ddart.net/mssql/sql70/dbcc_5.htm
Read about this
Extra resource
http://www.h2database.com/html/main.html This contains SQL grammar for most queries.
Regards
|
|
|
|