How to get the private and public key?

there is my code,i want to get the public key and the private key �Cbut i could not find the the approprite method to solve the problem.
import java.security.Key;
import javax.crypto.Cipher;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.Security;
public class PublicExample {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage:java PublicExample <text>");
System.exit(1);
byte[] plainText = args[0].getBytes("UTF8");
System.out.println("\nStart generating RSA key");
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(512);
KeyPair key = keyGen.generateKeyPair();
System.out.println("Finish generating RSA key");
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", "BC");
//System.out.println("\n" + cipher.getProvider().getInfo());
System.out.println("\nStart encryption");
cipher.init(Cipher.ENCRYPT_MODE, key.getPublic());
byte[] cipherText = cipher.doFinal(plainText);
System.out.println("Finish encryption:");
System.out.println(new String(cipherText, "UTF8"));
System.out.println("\nStart decryption");
cipher.init(Cipher.DECRYPT_MODE, key.getPrivate());
/*i want to get the private and public key in this method ,but i found the result was not
the one i expected to get,how to solve the problem?
thanks in advance!
System.out.println("private key:" + key.getPrivate().toString());
System.out.println("public key:" + key.getPublic().toString());
byte[] newPlainText = cipher.doFinal(cipherText);
System.out.println("Finish decryption:");
System.out.println(new String(newPlainText, "UTF8"));
thanks in advance!

System.out.println("private key:" +
" + key.getPrivate().toString());
System.out.println("public key:" +
+ key.getPublic().toString());
key.getPrivate() returns an instance of PrivateKey and key.getPublic() returns an instance of PublicKey. Since PublicKey and PrivateKey are interfaces then they will return one of the concrete implementations. Check out the Javadoc for PublicKey and PrivateKey.
When you know which concreate implemenation you have then you can use the methods on that object (by appropriate casting) to find the information you want.

Similar Messages

  • How to get the private and public keys to use recaptcha?

    I have registered with google to get a recaptcha for my website. All I got was the site key and secret key! Though I need to get the public and private key for muse!

    Hello,
    Please use site Key as "Public Key"and Secret key as "Private Key".
    Regards
    Vivek

  • How usnig manuplate the Import and export Key word.

    How usnig manuplate the Import and export Key word? and
    how do the clear of those variable?

    HI ,
    For IMPORT Keyword :---
    To retrieve data from the global memory area, use the IMPORT statement.  The most basic form of the IMPORT statement is:
    IMPORT <variable> FROM MEMORY.
    To give the variable a different name in your program from what it is called in the global memory area, use the TO clause.  You must define the local variable name with a DATA statement in your program.  The format is:
    IMPORT <global var> TO <program var> FROM MEMORY.
    As with the EXPORT statement, you can specify multiple variables per statement, and you have the option of specifying which cluster ID you wish to import from.
    After each IMPORT statement, SY-SUBRC is set to indicate whether or not the cluster ID you specified exists (but not whether specific variables were imported specifically).  SY-SUBRC is zero if the cluster exists.
    It is also possible to IMPORT and EXPORT to database tables .
    ABAP memory that is used to store exported data is user and transaction specific, so when passing data between programs in this manner you must make sure that transaction boundaries are not crossed. Otherwise the contents of this memory will get destroyed and will not be available to the importing program.
    For Export Keyword :---
    The EXPORT statement moves data from your program into a global memory area.  The most basic form of the EXPORT statement is:
    EXPORT <variable> TO MEMORY.
    This places the specified variable into a global memory area that another program can later read using the IMPORT statement.
    You may specify multiple fields in the same EXPORT statement.  For example:
    EXPORT KNA1-KUNNR KNA1-BUKRS TO MEMORY.
    You can give variables a different name in the global memory area using the FROM clause.  For example, the following code exports SY-SUBRC and gives it the name RETVAL in the global memory area:
    EXPORT RETVAL FROM SY-SUBRC TO MEMORY.
    You can specify a cluster ID when exporting data to memory.  You can freely choose the name of the cluster ID, which can be up to 32 characters long.  Each cluster ID specifies a particular area in memory.  Each time you EXPORT data to the same cluster ID, all data previously written to that ID is erased.  For example:
    EXPORT SY-SUBRC TO MEMORY ID u2018LJS1u2019.
    Hope u understand
    Thanks
    Shambhu

  • I have an Apple I Phone 4S which is great but, can someone help me how to get the photos and videos to my PC which runs on MS XP. I would like to be able to edit and copy to a DVD.

    I have an Apple I Phone 4S which is great but, can someone help me how to get the photos and videos to my PC which runs on MS XP. I would like to be able to edit and copy photos and videos to a DVD.

    Connect your iPhone to your computer. Tp your pc should recognize your iPhone as a camera. Use what ever application you have on the pc to transfer files from a camera to your computer.

  • How to find modulus(n) and public key exponent(e)Sor

    I did the following code:
    import java.security.*;
    class keypair
    public static void main(String args[])
    try {
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(1024);
            KeyPair keypair = keyGen.genKeyPair();
            PrivateKey privateKey = keypair.getPrivate();
            PublicKey publicKey = keypair.getPublic();
            System.out.println(publicKey);
    catch (java.security.NoSuchAlgorithmException e) {
    }It produced the following output:
    E:\java>java keypair
    Sun RSA public key, 1024 bits
    modulus: 104598424699919432698042124865237006532583108525971624656815039032375
    *68185931249899603942873174007833898125332457427834491991685017307342129730049040*
    *85039266578793603162921901877391682504673766949037045217194339504369288262569809*
    *64618725280325930282787918761626276736975012559809247463223114702205350103039131*
    public exponent: 65537
    How to parse modulus(n) and public exponent(e) from this output?
    Similarly when i print private key, it produces the following output:
    E:\java>java keypair
    Sun RSA private CRT key, 1024 bits
    modulus:          124578817060208658480856678950235831207402457067036419284514
    *60119309486714863949162442643168408523979997168613499493638925829235693238993015*
    *36861462235708805467117179894466762970147852286192228334073408407380525883650965*
    *26200137024900438305422984852314541271126647102071346646999343089444655087519613*
    *147762713*
    public exponent:  65537
    private exponent: 938527844532658207604152892230342202756165450473898580852699
    *91069268853864683730106242370135012901790500054313488639918623825755509450966957*
    *25996151023641565209086629652161258725723528561744214714448113895688480371394495*
    *69970533766968335232379493089928062691491508442909468663624841001227918721233934*
    *90451285*
    prime p:          128112715803862066344339615342766575233634768887073748611821
    *70613165835421234259251719401979554816266892921739504796026180704477109334458578*
    *924582228715587*
    prime q:          972415706579323990162180646771186062588725555167352041581263
    *11833654947284058644791019214876691698044764118648637510099163830088827138987158*
    *06445271350899*
    prime exponent p: 102053075991522697645186596252261651077210381075096084960080
    *01572103324900452503753532555651687424478224695551102238145517644352533224205327*
    *850477437666141*
    prime exponent q: 668659136319899226645386130685620335239039277715133737489656
    *56694442226518700929665796129185316864860876985624927131126216000167126890435269*
    *81971346772483*
    crt coefficient:  337801534982286124613379128447816812903646302193598735486466
    *78634104811105616496519276355880320340688935923186965279527763125244878069735173*
    *60542121091569*
    E:\java>
    From this output how to parse n and d, where d is the secret exponent or decryption exponent? Thanks in advance. Apologies, for posting in this forum instead of cryptography forum.
    Edited by: sowndar on Nov 28, 2009 3:12 AM

    sowndar wrote:
    From this output how to parse n and d, where d is the secret exponent or decryption exponent? Why do you think you need to parse anything? Why do you need the modulus and exponents?
    P.S. Extract the public and private keys from the key pair, cast them to RSAPublicKey and RSAPrivateKey as appropriate then look at the methods of classes RSAPublicKey and RSAPrivateKey to see how to get modulus and exponents.

  • How to get the system specific hardware key.

    Hi all,
        I want to get the System specific hardware key(May be Hard disk related key which is unique for every System.) .Now i need to get it using a java program. if possible send me the related links and sample source code. pls help me out to resolve this issue.
    Regards,
    Kiran.

    hi,
       I can able to get the Mac address of computer using the java program. But when i am running a software called "PCQualifier.exe" i am getting the parameters like "uniqueID" and "unique code". so where and how he is getting those things please help me to get those things using a java programme. Any how i am sending the results that i have got after ruuning PCQualifier.Pls kindly help me out to resolve this issue.
    Computer Name  JAVADEV0005  
    Operating System  Windows XP 5.1 build 2600 (Service Pack 2)  
    Ethernet Details                   Name [00000008] Broadcom NetXtreme Fast Ethernet                   Adapter Type Ethernet 802.3                  
    MAC Address 00:11:25:F2:98:EF   
    Hard Disk Capacity    Total      39.06GB  
                          Used       84 %  
                          Free       6.16GB  
    RAM Capacity    Total      502 Mbyte  
                    Used       69 %  
                    Free       154 Mbyte  
    CDROM Status  CD-ROM Drive Present  
    USB Information   
    Total system supported Ports 0  
    Total Physical Ports 0  
    Total Devices Connected 0  
    Total Free Ports 0  
    Unique ID  5790315021  
    Unique Code  FNVVEFEFHIKO
    Thanks & Regards
    Kiran.

  • How to get the values and attributes of Longlived processes by using ProcessID.

    Hi Experts,
    For  every process we creates, LC ES2 creates processID.
    we know that if you creates  a long lived process, all  the  values which are in proces will be stored some where  in DB.
    Here my requirement is by using  processID I need to get all/some values/variables stored in database.
    I am not able to get values using processID. Here I don't have clue on  how to get the values.
    Please tell me  how to get the same by using  Process Management. Link/guide would be helpful
    Thanks
    Praveen.

    Searchable means you can put a filter criteria on it (e.g. where amount > 50000)
    Visible means you can add have this column returned as an output (and therefore you can add it as column in listview and see it in Task Details).
    These two attributes were provided so that queries could be done against the process variables, but the exact contents of the variables are not allowed to be seen.

  • How to get the recipient and Note for recipient in Medium 7 Simple Mail?

    Dear friends,
    I'm trying to send the shipment in the form of PDF attachment to the assigned user. I'm wondering how can I get the receiver and the note(which should be the content of the email) which can be configured in the "Communication Method"?
    Thanks,
    YiNing

    Well, the maintained text doens't  show up as the text of the mail content. So I'm actually asking how can I (from which variant in program) I can get this text. Or is there any standard program shows me how to do this?
    Thanks!

  • How to get the table_name and its count(*) in a SQL

    Hi,
    Can anybody tell me how to write a sql to get the table_name and its count(*) in a SQL:
    Output should be:
    table_name count(*)
    XXX 261723
    YYY 3343
    Regards,
    G. Rajakumar.

    hello
    there r a lot ways
    i'll suggest u two of them
    1) the following dynamic sql procedure
    DECLARE
    TYPE array_type IS TABLE OF VARCHAR(30);
    TYPE cur_typ IS REF CURSOR;
    c1 cur_typ;
    count1 integer;
    tab_arr array_type;
    querystr varchar2(200);
    begin
    SELECT table_name bulk collect into tab_arr FROM sys.all_all_tables ;
    FOR I IN tab_arr.first..tab_arr.last LOOP
    DBMS_OUTPUT.PUT(TAB_ARR(I));
    querystr := 'select count(*) from ' ||TAB_ARR(I);
    open c1 for querystr;
    fetch c1 into count1;
    EXIT WHEN c1%NOTFOUND;
    dbms_output.put_line(count1);
    END LOOP;
    close c1;
    END;
    2) or use ANALYZE to analyze the tables and get the number of rows in the NUM_ROW column of DBA_TABLES view.
    if u still have any problem mail me at [email protected]
    shalini

  • How to get the Folders and subfolders collection in Project Manager

    Hi,
    I am trying to get the folders and subfolders collection in Project Manager, so that I will be able to loop through the collection and be able to create a project under the appropriate folder.
    Any suggestions?
    Thanks.
    Bhanu

    Anything you do without submitting to form has to be done on the client side (ususally by JavaScript) using data which has been send already from the server.
    With JavaScript you can do quite a bit. You can download tables which don't necessarilly appear on the screen, loading them into JavaScript arrays by dynamically generating javascript. Then you can pick up events like drop-box selection and use these tables to chose what you do next (e.g. preloading other fields, setting drop box content etc.).
    Or, you can cause forms to be submitted when actions like a selection happen without the user clicking a button. It's generally a matter of how much data you'd need to transmit.
    Another posibility is to use a Java applet, which can generate requests to the server and handle the results as it chooses. That are a number of problems with that but occasionally it's the best solution.
    What you can't do is to handle user input inside a JSP. The JSP has come and gone before the user even gets to see your form.

  • How to get the constraintlist and column name in a table?

    Hi,
    can anyone please tell me how to get the constraint type ,and it's imposed on columns names in a table.
    Thanks,
    Deekay

    Deekay wrote:
    can anyone please tell me how to get the constraint type ,and it's imposed on columns names in a table.To get constraint type:
    select constraint_type from user_constraints where constraint_name = 'YOUR CONSTRAINT NAME';To get constraint columns:
    SELECT column_name from user_cons_columns where constraint_name = 'YOUR CONSTRAINT NAME';SY.

  • How to get the number and response time of HTTP request through Weblogic?

    hi,
    does anybody know how to get the HTTP request information through Weblogic server, such as the number of HTTP request in 1 min and the average response time of request in 5 mins ?
    Or is there anyway i can do it through monitoring and get these data then? If so, please help tell me.
    Thanks in advance
    BTW, we don't have the 3rd-party monitoring tool here.

    Hi,
    tables: usr02, usr41.
    data: OPCODE_MODE_COUNT(1) TYPE X VALUE 3,
          modes like sy-index,
          u_MODES LIKE MODES.
    select * from usr02.
      select * from usr41 where BNAME = usr02-bname.
        CALL 'ThUsrInfo' ID 'OPCODE' FIELD OPCODE_MODE_COUNT
          ID 'TID' FIELD usr41-TERMID
          ID 'MODES' FIELD MODES.
        IF SY-SUBRC = 0.
          u_MODES = u_MODES + MODES.
        ENDIF.
      endselect.
      if sy-subrc = 0.
        write:/ usr02-bname, u_MODES.
      endif.
      clear u_modes.
    endselect.

  • How to get the lock and block occured for the full day

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?
    Why would you like to collect information about locks and let me tell you, you cannot collect information about ALL locks which were taken and even thinking about it is pointless.
    Coming to blocking if you have heavy system with huge concurrency there is bound to be blocking which is necessary and good for RDBMS but if the blocking remains for long time then this is a issue.
    There is DMV sys.dm_tran_locks which tell you what all locks are being taken. You can see various examples mentioned in DMV online documentation and can schedule the query to run every 5
    mins and insert its record in table which you can refer at end of the day.
    This task would be made very easy if you have Monitoring tool which gives you information in your mail every time blocking occurs I have Spotlight in my environment.
    If you are looking for doc for troubleshooting blocking  below is one you can refer
    http://support.microsoft.com/kb/224453
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

  • How to get the latest and valid BOM item entry from STPO

    hi,
    may i know with what condition we can get the latest and valid BOM item entry from STPO table?
    i have STLNR and IDNRK as a input. But i realized that it would return multiple entry due to the combination of  valid-from and valid till date.
    can i use stlnr,idnrk and stpoz (with the latet counter) to get the latest and valid BOM entry?
    thank you.

    Hi
    You can get the latest BOM either by using the latest valid from date DATUV or latest internal counter STPOZ
    Regards
    Shiva

  • How to get the Title and Tcode of a Program during run time

    Hello,
    I am new to abap and I have this question please. Is the a way to get the title, Tcode and Author of a program during run time? I would like to get the name and title of a program or a view or an include during run time.
    Using table TADIR, you can only get the object_name and the author. Is the a way for me to get the Title of the repository object and any Tcode if any is available for the case of a program?
    I loop forward for your respond.
    Thank you.
    Sabina

    You can get it by accessing SYST.
    SY-TITLE for Title
    SY-TCODE for Tcode
    I don't think there is any field in SYST for the Author.
    To get the author name you can use the TRDIR table.
    Regards,
    Naimesh Patel

Maybe you are looking for