Shah Jenish

Greenhorn
+ Follow
since Feb 19, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Shah Jenish

Hi All,

We have a pom.xml file with few dependencies belongs to two repositories. But there is one dependency jar which is part of both the repositories and at the same path only at both the place.

Is there any way where I can mention in Pom.xml that particular dependency should be taken from a particular repository only?

Thanks,
Jenish
10 years ago
Hello All,

I have an instance in my application. Where I need to get one parameter from URL. There is possibility that whatever I get as string can be encoded or can be not encoded.

And if its encoded I have to decode it before using.

Can anybody please suggest me the way by which we can identify if particular string is already UTF-8 encoded or not?

Thanks,
Jenish
10 years ago
Hello All,

I have once scenario where I need to convert localized string amount to parse and make it long amount.

Example: In russia, people write 1000 as "1 000".
Now what I need to do is to parse this "1 000" and get 1000.

Is there any way in java, which can identify if the particular string is localized price in some Locale and give us the normal long output?

Thanks,
Jenish
11 years ago
Hello All,

I have a string "US $2,000.00" in a string money. I want to pull out "2,000.00" from the string.

I am using string split to achieve that.

String money = "US $2,000.00";
String[] parts = money.split("$");
System.out.println(parts);

But of parts contains only one element with full string. It doesnt split the string in two parts one before the "$" and one after the "$".

Can anybody please let me know if I missed out to do something here?

Jenish
11 years ago
Hello All,

I have written simple program to show Longer Date.

I am using

DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.getDefault()).format( new Date()));

Now when I run this program on one of the Windows Server 2008 machine, this program shows me different timezone than the MSINFO32 returns on the machine.

Can anybody please tell me what could be the reason that Java returns different timezone than MSINFO32?

Thanks,
Jenish
11 years ago
This is the URL that I use to invoke my servlet from my applet

Code:

http://192.168.0.67/MyServlet?p1=団

As you can see, the parameter has a unicode character 団. So I use

Code:

URLEncoder.encode ( "団", "UTF-8" ) ;

and now my URL becomes

Code:

http://192.168.0.67/MyServlet?p1=%E5%9B%A3

However, from the servlet, calling

Code:

request.getParameter ( "p1" ) ;

already return some gibberish that cannot be decoded with URLDecoder. BTW, invoking

Code:

URLDecoder.decode ( "%E5%9B%A3", "UTF-8" ) ;

does give me the original unicode character. It`s just that the servlet has garbled the parameter before it can even be decoded. Does anyone know why?

Request.gerparameter doesnt decode parameter with UTF-8?
12 years ago
Hello All,

We have an application which has client and server mechanism.

Our application can be accessed by any internet browser on any machine of the network but there is only one server in the network.

One of the functionality in the application is described below.

We do have one link in our application webpage. When user clicks on that link, the request goes to the server component which is running on different machine. Now server process the request and in responce we do show some images in applet window at the customer webpage.

Now problem is, when the client machine browser has some lower version of Java, we are not able to show the image but only shows a blank page.

What we want to do is to show some specific warning message when we find that the Java version at client machine is lower than required.

Can anybody please let me know how can I achieve this?

Thanks in Advance,
Jenish
12 years ago
Hello All,

I have made jar file for my application. One of the class of my application uses BouncyCastleProvider class of BC jar.

I have created one folder "lib" in the same parent folder where my application jar is residing.

I have changed my machine CLASSPATH to point to this new lib folder. But when I run my application it gives me classnotfound exception.

But if I copy this BC jar file to my jre/lib/ext then everything works fine.

Can anybody tell me what I need to do to access BC jar file from my lib directory?

Thanks in Advance,
Jenish
12 years ago
Nope I did not un-jared anything..

I am using Eclipse IDE. I added BC jar in my class path of the Eclipse Project because my class uses BC jar classes.

Now when I create runnable jar in eclipse, it automatically un-jared BC jar and add classes in executable jar.

Can you please suggest a way to keep application and BC jar separate?

Thanks in Advance,
Jenish
12 years ago
Hello All,

I have developed an application in which I have used the Cryptography with the help of BountyCastle.jar.

I also had a line Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

Everything works fine when I execute the program from Eclipse.

But when I made executable jar for my application which internally has BouncyCastle jar and execute the jar,

I am getting exception

JCE cannot authenticate the provider BC
java.lang.SecurityException: JCE cannot authenticate the provider BC
at javax.crypto.Cipher.getInstance(DashoA13*..)

Can anybody please guide me how can I solve this problem?

Thanks in Advance,
Jenish
12 years ago
Hey it worked fine I just changed my JRE version..

Thanks a lot for this wonderful program Carey..
12 years ago
Hi,

Thanks for your reply.

I have tried copy pasting the code from the thread you mentioned but I got the exception on line
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");

java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available
at javax.crypto.SunJCE_b.a(DashoA12275)
at javax.crypto.SecretKeyFactory.getInstance(DashoA12275)
at ftpserver.AESEncrypter.main(AESEncrypter.java:107)

Can you please tell me what is wrong with my code?

Thanks in Advance,
Jenish
12 years ago
I have written a below program to encrypt a file with AES 128 algorithm. This code works fine. It does encrypt and decrypt file successfully..

Here in this code I am generating SecretKey in the main() method with the use of key generator. But can anybody please tell me how can I generate SecretKey based on user's password in the below program?

Thanks in Advance,
Jenish

import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;

import java.security.spec.AlgorithmParameterSpec;

public class AESEncrypter
{
Cipher ecipher;
Cipher dcipher;

public AESEncrypter(SecretKey key)
{
// Create an 8-byte initialization vector
byte[] iv = new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};

AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
try
{
ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

// CBC requires an initialization vector
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
}
catch (Exception e)
{
e.printStackTrace();
}
}

// Buffer used to transport the bytes from one stream to another
byte[] buf = new byte[1024];

public void encrypt(InputStream in, OutputStream out)
{
try
{
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);

// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}

public void decrypt(InputStream in, OutputStream out)
{
try
{
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);

// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}

public static void main(String args[])
{
try
{
// Generate a temporary key. In practice, you would save this key.
// See also e464 Encrypting with DES Using a Pass Phrase.

KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128);
SecretKey key = kgen.generateKey();

// Create encrypter/decrypter class
AESEncrypter encrypter = new AESEncrypter(key);

// Encrypt
encrypter.encrypt(new FileInputStream("E:\\keeper.txt"),new FileOutputStream("E:\\Encrypted.txt"));
// Decrypt
encrypter.decrypt(new FileInputStream("E:\\keeper.txt"),new FileOutputStream("E:\\Decrypted.txt"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
12 years ago