How to get password as string back from encrypted password byte array.

Hi All,
I am storing encrypted password and enc key in the database.(Code included encryptPassword method for encryption and validatePassword method for validating of password). Problem is that for some reason i need to show user's password to the user as a string as he/she entered. But i am not able to convert the encrypted password from D/B to original String.
Tell me if any body know how to get the string password back from the encrypted password byte array after seeing my existing encryption code.
//********* Code
private Vector encryptPassword(byte[] arrPwd)
try
// parameter arrPwd is the password as entered by the user and to be encrypted.
byte[] encPwd = null;
byte[] key = null;
/* Generate a key pair */
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024, random);
KeyPair pair = keyGen.generateKeyPair();
PrivateKey priv = pair.getPrivate();
PublicKey pub = pair.getPublic();
/* Create a Signature object and initialize it with the private key */
Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
dsa.initSign(priv);
/* Update and sign the data */
dsa.update(arrPwd, 0, 12);
/* Now that all the data to be signed has been read in, generate a signature for it */
encPwd = dsa.sign();
/* Now realSig has the signed password*/
key = pub.getEncoded();
Vector vtrPwd = new Vector(2);
vtrPwd.add(encPwd);
vtrPwd.add(key);
return vtrPwd;
catch (Exception e)
private boolean validatePassword(byte[] arrPwd,byte[] encPwd,byte[] key) throws RemoteException
try
// arrPwd is the byte array of password entered by user.
// encPwd is the encrypted password retreived from D/B
// key is the array of key through which the password was encrypted and stored.
X509EncodedKeySpec KeySpec = new X509EncodedKeySpec(key);
KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
PublicKey pubKey = keyFactory.generatePublic(KeySpec);
/* Encrypt the user-entered password using the key*/
Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
sig.initVerify(pubKey);
/* Update and sign the password*/
sig.update(arrPwd, 0, 12);
return sig.verify(encPwd);
catch (Exception e)
Help upto any extent would be appreciated.
Thanx
Moti Singh

Hi All,
I am storing encrypted password and enc key in the
database.(Code included encryptPassword method for
encryption and validatePassword method for validating
of password). Problem is that for some reason i need
to show user's password to the user as a string as
he/she entered. But i am not able to convert the
encrypted password from D/B to original String.No, you are not encrypting the password in your code, you are merely signing it.
Tell me if any body know how to get the string
password back from the encrypted password byte array
after seeing my existing encryption code.It is impossible to retrieve the original text out of a signature.
You should read up on some encryption basics in order to understand the difference between signing and encrypting. Then you can find examples of how to encrypt something here: http://java.sun.com/j2se/1.4/docs/guide/security/jce/JCERefGuide.html.
Actually there is one class specifically for keeping keys secure, KeyStore http://java.sun.com/j2se/1.4/docs/api/java/security/KeyStore.html
- Daniel

Similar Messages

  • Help:How to get a java String value from a C char array?

    Hi,everyone,could you help me?
    the following is a C struct that i want to recieve a short message:
    struct MO_msg{
    unsigned long long msgID;          //Message ID
    char      dest_id[21]; //Destination Mobile Phone Number
    char      service_id[10];     //
    Now I want to put the "dest_id " value of this struct into a Java String variable.But I dont know how to implement it!
    The following is a block of source code that i implement this functions.But it cant get a String value ,and throw out a Exception:
    java.lang.NullPointerException
    at java.lang.StringBuffer.append(StringBuffer.java:389)
    JNIEXPORT jint JNICALL Java_md_EMAP_thread_RubeMOTSSX_getMO
    (JNIEnv * env, jobject obj, jint connId, jobject mo){
         struct MO_msg MO;
         tssx_cmpp_api_debug_flag = 1;
         int result = CMPP_Get_MO((int)connId,&MO);
         if (result == 0){
              jclass cls = (*env)->GetObjectClass(env,mo);
              jfieldID msgId = (*env)->GetFieldID(env,cls,"msgId","J");
              jfieldID dest_Id = (*env)->GetFieldID(env,cls,"dest_Id","Ljava/lang/String;");
              jfieldID serviceId = (*env)->GetFieldID(env,cls,"serviceId","Ljava/lang/String;");          
              (*env)->SetLongField(env,mo,msgId,MO.msgID);               
              (*env)->SetCharField(env,mo,dest_Id,*destId);
              (*env)->SetCharField(env,mo,serviceId,MO.service_id);
         return result;
    Please help me!Thanks!

    bschauwe:Thank you for your help!
    Yes,just as you say,using NewString Or NewStringUTF can import a C char array into a Java String variable! But now I have another question,when i use these two functions ,i found that it cant deal with Chinese character!
    do you have such experiences to deal with another language charset?if you have ,can you tell me how to deal with it.

  • How to get my camera roll back from iCloud?

    I restored my iPhone and now I need to get my camera roll back from iCloud..please tell me how to do that..Thank you

    That's true. You can only restore complete backups.
    I got my pictures back, the ugly way though. What I did:
    - made an iCloud backup of my phone (only 2GB instead of the earlier 4GB, because the camera roll was empty)
    - restored my last iTunes backup, this was a month old. It was made right before i upgraded to iOS5.
    - My pictures were back on my iPhone so i downloaded them to my PC.
    - Then I restored the iCloud backup from my phone. The one I made before I restored the iTunes backup.
    The pictures where gone again, but at least I had them on my PC.
    I don't trust iCloud backups anymore. The backup itself holds all your settings and remembers which apps and data you had installed. But it went wrong when it had to redownload the pictures from the cloud. It was a hard lesson learned. From now on I'll backup my pictures once in a while. I was used to what Apple promises: that everything "just works". No, it doesn't.

  • How to get my Paid Apps Back from a Apple ID which i cant Download Anything

    Hi,
    My Mum recently changed her credit card which led her old one disable. Every time i type my mums old security code on her credit card it would say its not vaild. Is there a way i can get my paid books, movies and apps back from my old apple id.
    Its annoying that i spent about £100 on Apps books and movies now i cant access them
    Thanks

    Aideed wrote:
    Hi,
    My Mum recently changed her credit card which led her old one disable. Every time i type my mums old security code
    As suggested, type the new security code on the back of the new card.
    Is there a way i can get my paid books, movies and apps back
    Back? Did you delete them in iTunes?
    from my old apple id.
    Old AppleID?
    Did you create a new AppleID?

  • My iPhone is stolen. How can I get my address book back from the iCloud? I should have synchronized my iPad address book. However, I loss some recent contacts from iPhone.

    My iPhone is stolen. How can I get my address book back from the iCloud? I should have synchronized my iPad address book. However, I loss some recent contacts from iPhone.

    I use my iPad to get the address book backed up by iCloud from my iPhone. However, I cannot see the recent new contacts from my iPad. Is there anyway to check the iCloud server to see if my address book backup from my iPhone is still there?

  • HT204406 I tuned on IMatch, hated it, so turned it off. I want to get all my music back from the Cloud so that it sits locally on my hard drive. How do I do that?

    I tuned on IMatch, hated it, so turned it off. I want to get all my music back from the Cloud so that it sits locally on my hard drive. How do I do that?

    Hello Tina,
    Thank you for the question.  It sounds like you would like to download your songs from iTunes Match.  You can do this by turning iTunes Match back on and clicking the cloud icon with the downward facing arrow next to the songs that you would like to download to your computer:
    Available for Download
    This icon appears when a song is available in iCloud and hasn't been downloaded to your local library.
    iTunes Match: Understanding the iCloud Status icons
    http://support.apple.com/kb/ts4124
    Thank you for using Apple Support Communities.
    Best,
    Sheila M.

  • I tuned on IMatch, hated it, so turned it off. I want to get all my music back from the Cloud so that it sits locally on my hard drive. How do I do that?

    I tuned on IMatch, hated it, so turned it off. I want to get all my music back from the Cloud so that it sits locally on my hard drive. How do I do that?

    tina.rogers wrote:
    this seems to me to indicate that Match copied the library up into the cloud and it no longer physically exists on my HDD???
    No, this is not what iTunes Match does. When you enable the service it leaves all the original files right where they are and mirrors your library in the cloud by either matching tracks to tracks available on the iTune Store or uploading tracks to the cloud. The service does not delete files from your HDD.
    I am unsure what you mean by "library icon" or "itunes library file" but if you mean the iTunes Library.itl file the size of that file is irrelevant.
    Before you enabled the iTunes Match service approximately how many songs were in your iTunes library and where were they stored? On the internal HDD of the computer, or on an external? Also, do you have backups?

  • How can I get my Aperture library back from the Photos application?

    As stated above, How can I get my Aperture library back from the Photos application?  I'm not a fan of Photos right now and haven't used iPhoto in years, so that wasn't a loss... I didn't realize when I gave Photo's access to my Aperture library, I was going to lose it...
    I want to get it back, any suggestions?
    Thanks again!
    MacTeacherMN

    what means ..."Once you open the Aperture library back into Aperture..."? What do I need to "klick" in order to getting back my old Aperture Project structure....

  • PC crashed and now using a different PC.  How do I get my iTunes library back from the failed PC on the PC being used now?

    PC crashed and now using a different PC.  How do I get my iTunes library back from the failed PC on the PC being used now?

    Extract the hard drive from the faulty computer and recover the library from it or see Recover your iTunes library from your iPod or iOS device. (At least one link in there may be useful even if you don't have such a device.)
    tt2

  • How to get list of file names from a directory?

    How to get list of file names from a directory?
    Please help

    In addition, this:
    String filename = files;Should be this:
    String filename = files;
    That's just because he didn't use the "code" tags, so [ i ] made everything following it become italicized.                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to get the; popular tag: back in safari. Deleted it.

    How to get the POPULAR tab back in safari after deleting it. Thanks for the help.

    You have to pass a parameter. An id is good.
    Of course you have to get an id from somewhere in the result set right?
    <a target="_top" rel="contents" rev="contents" class="fordynamiclabel" href="ASCMasterTwo.jsp?id=<%= rSet.getString("id") %>"><%=rSet.getString(1) %></a></td>Then you call
    request.getParameter("id");
    and look up the values related to that id in the database.

  • How to get the failover partner name from C++ client

    Hi All,
    I have configured the mirroring session for my application.
    I want to modify the connection string with failover partner name.
    Could any one please let me to know how to get the failover partner instance from C++ client dynamically.
    Thanks,
    Prasad.

    Are you looking for this?
    http://www.connectionstrings.com/sql-server-2012/
    http://stackoverflow.com/questions/25534972/auto-failover-multiple-connections-to-mirror-database-when-principal-goes-down

  • Insurance claim for music - how to get print out of purchases from itunes

    Can any one help me as my Hard Drive crashed yesterday and i've lost all my Music, movies etc purchased from itunes in the last 2 years. Need to know how to get a detailed print out from itunes to prove purchase and claim on insurance. And yes i know i should have backed up my recent files...

    The only way is to log into your iTunes Store account (you'll need a working computer with iTunes installed, of course), go to your Purchase History, and do a screen capture of each successive page. There's no way to print out a full listing of all your purchased in one go.
    Regards.

  • CallableStatement: how to get prepared call string?

    How can I get the parameter string that is set via prepareCall() from a CallableStatement?
    String call = "{call sp_irecord (?,?,?)}";
    CallableStatement cs = connection.prepareCall(call);
    //later, when 'call' is not known but cs:
    String originalCall = csc.get???();
    //how to get the call string from the callable statement?

    i don't mean the parameter names or values, i mean the string that you set with the prepareCall() method:
    String call = "{call sp_irecord (?,?,?)}";
    CallableStatement cs = connection.prepareCall(call);
    System.out.println("Call string: "+cs.getCallString());with the method getCallString() (that i invented and that i'm looking for) should return the exact string. The output of the example above should be:
    Call string: {call sp_irecord (?,?,?)}

  • HT2490 does anyone know how to get my 'google' page back when I click on safari- it was always there and now comes a panel of panes with my 'top sites'- it is so aggravating...

    does anyone know how to get my google page back when I open safari??.... it is gone and I get a full page of 'top sites' instead... it is so frustrating! appreciate the help if anyone knows!

    Safari preferences / General tab

Maybe you are looking for

  • Problems Setting-up Airport Express to Play Music thru External Speakers

    Hi: I have an HP dv6500z laptop connected to an HP printer C6280 via LinkSys wireless network using the LinkSys 54G router and PrintServer. It works fine. I purchased an Apple Airport Express and want to connect it to this network so that I can play

  • Getting songs and videos back I've already purchased

    I have the 2nd generation iPod touch. I just upgraded my old software 3.1.1 to the new 4.1 software. It took about 5 hours to back up my iPod do all this other stuff. Apparently it restored it to factory settings so I lost all my videos and songs. I

  • CPU goes 70% with h.264 while NetStream is published with H264 codec

    Hi,      I am creating an video conferencing tool in which I am using H.264 video codec for stream. When I tried to publish video with 640*480 and video quality= 90 and FPS =15, My machine CPU usage  crosses 70% mark. while with same setting I publis

  • Where is the box APPLY when I have syched my photos on iPad?

    I Attached my iPad to computer this morning to take off some photos as I was running out of space, so clicked on some albums but there is no APPLY button to finish off........where is it?

  • Info pack is hanging for longer times

    Hi Gurus, I had a Info pack which will fetch the data from IBM Data stage to SAP BW,When i'm executing the load jobs my info pack is in yellow for hours and message in Data stage is "APT_CombinedOperatorController,0: Logging delayed metadata.".Can an