Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

java.security.NoSuchAlgorithmException need Help!!!!!!!!!!

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is Encrypt/Decrypt example but clause
import java.io.*;
import java.security.*;
import javax.crypto.*;
class EncryptDecrypt {
public static void main(String args[])
{
try
{
// generate Cipher objects for encoding and decoding
Cipher itsocipher1 = Cipher.getInstance("DES");
Cipher itsocipher2 = Cipher.getInstance("DES");
// generate a KeyGenerator object
KeyGenerator KG = KeyGenerator.getInstance("DES");
System.out.println("Using algorithm " + KG.getAlgorithm());
// generate a DES key
Key mykey = KG.generateKey();
// initialize the Cipher objects
System.out.println("Initializing ciphers...");
itsocipher1.init(Cipher.ENCRYPT_MODE, mykey);
itsocipher2.init(Cipher.DECRYPT_MODE, mykey);
// creating the encrypting cipher stream
System.out.println("Creating the encrypting cipher stream...");
FileInputStream fis = new FileInputStream("b.txt");
CipherInputStream cis1 = new CipherInputStream(fis, itsocipher1);
// creating the decrypting cipher stream
System.out.println("Creating the decrypting cipher stream...");
CipherInputStream cis2 = new CipherInputStream(cis1, itsocipher2);
// writing the decrypted data to output file
System.out.println("Writing the decrypted data to output file " + args[1]);
FileOutputStream fos = new FileOutputStream("c.txt");
byte[] b2 = new byte[1024];
int i2 = cis2.read(b2);
while (i2 != -1)
{
fos.write(b2, 0, i2);
i2 = cis2.read(b2);
}
fos.close();
cis1.close();
cis2.close();
}
catch (Exception e)
{
System.out.println("Caught exception: " + e);
}
}
}
may me i not registered provider how to add provider or algorithm
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dorj,
I haven't worked on this cryptography yet.
But if you can go to google groups and enter the exception, you can find a lot of links.
I used to do like that, I copy my errors in the groups and will read the comments from others with the same/similiar postings. I have got many valuable information from this.
Thanks,
Maya
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi maya?
this is encode sample. working correctly. But i can't decode
do you now how to decode? I no any idea. u can download javax.crypto package from <a href="http://jsecom15.sun.com/servlet/EComActionServlet?StoreId=8&PartDetailId=JCE-1_2_1-G-F&TransactionId=Try&LMLoadBalanced=&LMLoadBalanced=" target="_blank">http://jsecom15.sun.com/servlet/EComActionServlet?StoreId=8&PartDetailId=JCE-1_2_1-G-F&TransactionId=Try&LMLoadBalanced=&LMLoadBalanced=</a>;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.io.*;
import com.sun.crypto.provider.*;
import java.util.*;
public class Encode
{
public static void main(String args[])
{
try
{
Provider sunJce = new SunJCE();
Security.addProvider(sunJce);
Cipher cipher1 = Cipher.getInstance("DES");
KeyGenerator KG1 = KeyGenerator.getInstance("DES");
KG1.init(56);
Key mykey = KG1.generateKey();
cipher1.init(Cipher.ENCRYPT_MODE, mykey);
FileInputStream fis=new FileInputStream("B.txt");
FileOutputStream fos=new FileOutputStream("C.txt");
byte[] input=new byte[5];
int a=-1;
String Line=null;
while ((a=fis.read(input))!=-1)
{
byte output[]=cipher1.doFinal(input);
System.out.println(Integer.toString(cipher1.getOutputSize(5)));
fos.write(output);
fos.flush();
}
fis.close();
fos.flush();
fos.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
this progarm convert 5 bytes to 8 byte. but i can't convert 8 byte to 5 byte. try this. i think
on line 20 change
cipher1.init(Cipher.ENCRYPT_MODE, mykey);
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dorj,
I haven't done any encoding or decoding. But I started my research on the topic.
Will this help you by any chance ?
http://developer.java.sun.com/developer/onlineTraining/Programming/BasicJava2/crypto.html
Please have a look at the algorithm ..
Thanks,
Maya
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Modify U'r program based on the following lines.
1. Install the Provider
2. Generate a key
3. Generate a Secret Key
4. Create a Cipher Instance
5. Initialize the Cipher(encrypt)
6. Use dofinal() to generate cipher text.
7. Initialize the same Cipher instance to decrypt.
Note - There is no need to create 2 Cipher instances for like U did in U'r program.
All the best

Originally posted by Dorj Galaa:
this is Encrypt/Decrypt example but clause
import java.io.*;
import java.security.*;
import javax.crypto.*;
class EncryptDecrypt {
public static void main(String args[])
{
try
{
// generate Cipher objects for encoding and decoding
Cipher itsocipher1 = Cipher.getInstance("DES");
Cipher itsocipher2 = Cipher.getInstance("DES");
// generate a KeyGenerator object
KeyGenerator KG = KeyGenerator.getInstance("DES");
System.out.println("Using algorithm " + KG.getAlgorithm());
// generate a DES key
Key mykey = KG.generateKey();
// initialize the Cipher objects
System.out.println("Initializing ciphers...");
itsocipher1.init(Cipher.ENCRYPT_MODE, mykey);
itsocipher2.init(Cipher.DECRYPT_MODE, mykey);
// creating the encrypting cipher stream
System.out.println("Creating the encrypting cipher stream...");
FileInputStream fis = new FileInputStream("b.txt");
CipherInputStream cis1 = new CipherInputStream(fis, itsocipher1);
// creating the decrypting cipher stream
System.out.println("Creating the decrypting cipher stream...");
CipherInputStream cis2 = new CipherInputStream(cis1, itsocipher2);
// writing the decrypted data to output file
System.out.println("Writing the decrypted data to output file " + args[1]);
FileOutputStream fos = new FileOutputStream("c.txt");
byte[] b2 = new byte[1024];
int i2 = cis2.read(b2);
while (i2 != -1)
{
fos.write(b2, 0, i2);
i2 = cis2.read(b2);
}
fos.close();
cis1.close();
cis2.close();
}
catch (Exception e)
{
System.out.println("Caught exception: " + e);
}
}
}
may me i not registered provider how to add provider or algorithm


 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David Bejjam
can you send me example code of encrypt and decrypt
 
David Bejjam
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dorj,
Pl.s send me U'r email address so that I can send the code.
David
 
Dorj Galaa
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dorj_d@yahoo.com
 
David Bejjam
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dorj,
Hope U got the code.
All the best.
 
reply
    Bookmark Topic Watch Topic
  • New Topic