How to instantiate public key

hi,
I have a problem when I try to instanciate a RSAPublicKey from javacard with this code :
publicKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024, false);
this returns the error code 6f 00.
please help again!

the first problem have been already fixed and the value returned by getReason is 1
here my public exponent and modulus arrays
private static final byte[] exponentPublicKey = {1, 0, 1};
private static final byte[] modulusPublicKey = {
          0, -48, -96, -44, -25, 111, 122, 92, 11, -79,
          124, -63, 97, -126, -60, -10, -44, -99, -20, 40,
          60, 82, -25, -85, -96, 46, 119, 91, -4, 122,
          -33, 88, 1, 51, 113, 20, 122, 101, -79, 59,
          -127, 53, 90, 64, -94, -44, -94, 18, 74, 89,
          62, 33, -66, 0, 0, -89, -11, -111, 10, 48,
          -27, 73, 88, 12, 89};

Similar Messages

  • How to get Public Key Remainder?

    Hi Friends..
    Sorry, i have a little doubt regarding the Public Key Remainder..
    What is Public Key Remainder used for?.. is it a part of Public Key?.. How to get it from Public Key, especially in Java?
    As far as i know that the Public Key is constructed with Modulus and Exponent, and with this we can Encrypt and Verify data was signed by Private Key..
    In Java, we can expose Public Key's modulus and public exponent using RSAPublicKey, there's no method to expose Public Key's Remainder..
    Please help me regarding this..
    Thanks

    Leonardo Carreira wrote:
    Hi Shane,
    Thanks for your reply.. :)
    safarmer wrote:
    In that case the exponent and remainder are you public key (exponent and modulus) and the certificate is defined in the definitions section of Book 3. It is a secure way of verifying the public key and it's owner through a trusted certification authority.
    EMV Book 3 tends to use Remainder and Modulus interchangeably.You mean, the Issuer (in this case one of E,M, and V) should provide 2 certificates for 1 card?..
    This is implemented on SDA or DDA?..
    Sorry, i'm still have no idea..
    The Remainder and Modulus should be used interchangeably?..
    How the Host and Card can decides in each transaction whether it will use Remainder or Modulus?..I mean that the terminology is used interchangeably. They refer to the same thing as far as the actual key is concerned.
    Cheers,
    Shane

  • How to obtain public key from a .crt file

    Hi
    I am new to cryptography Please correct me if my understanding regarding the digital signature is correct and i need help to get the public key.
    I have a x.crt file which contains following fields
    1) x
    2)y
    3) Certificate
    this certificate contains following fields
    certificate version
    owner id
    name
    public key
    signature (which is obtained by signing from start of x.crt till public key with private key)
    now i need to verify whether the signature for that i need to get the public key & signature from this .crt file. Is it how i need to verify the certificate ?? please help me as I am a newbie in cryptography

    Hi all
    Thanks for the reply
    So to get the public key now i used the following code
    byte[] dataPub = new byte[256]; // size of the public key
    try {
                        byteArrayInputStream.read(dataPub);
                   } catch (IOException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
              BigInteger modulus = new BigInteger(dataPub);
         BigInteger exponent = new BigInteger("65537"); // specified in the document
         RSAPublicKeySpec rpks = new RSAPublicKeySpec(modulus, exponent);
         KeyFactory kf = null;
                   try {
                        kf = KeyFactory.getInstance("RSA");
                   } catch (NoSuchAlgorithmException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
         try {
                        pk = kf.generatePublic(rpks);
                        System.out.println("Pb Key----------------:"+pk.toString());
                   } catch (InvalidKeySpecException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
    When I convert the pk.toString I am getting a negative modulus value . Can the modulus value be negative ??
    Edited by: 800317 on Oct 8, 2010 5:51 AM

  • Get user public key (ssh) from MDS 9509

    how can get public key from a user on MDS 9509?

    I'm not sure exactly what you are looking for, but to create keys for SSH, you will want to enable SSH like this:
    ssh server enable
    Then, you can generate a key like this:
    ssh key
    Or to specify the key for a user, it would be like this from the CLI:
    username ssh

  • 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.

  • How does a public/private key encrypt and decrypt each other?

    I understand the logic that when a communication takes place both parties pass their public keys to each other which is used to encrypt all messages. Once the party receives the messages the private key is used to decrypt them however I'm wondering how a private key is generated from a public key. If the private key is based on an algorithm wouldn't each party be able to generate what the other person's private key would be based on the public? Wouldn't a third party?

    How the public and private keys are generated depends on what public key cryptosystem is being used, but in general the private key cannot be derived from the public with a computationally feasable algorithm, while the public key can be derived from the private key very quickly. Two examples:
    RSA: private keys are 2 primes, p and q, and an encryption exponent d. Public key is the product p*q, and an encryption exponent e. How does the attacker get p and q, or d, from n and e? The best attack known against this (for properly chosen p, q, and d) is factoring. Factoring can be made infeasable by choosing the primes to be large enough.
    Diffie-Hellman: a prime modulus p and a base g < p is known by everyone (including the attacker). The private key is an integer x chosen randomly, 2 <= x < p-1 (there are better ways to choose x). The public key is g^x mod p. How does the attacker get x from g^x mod p? Again, the best known attack is one that is computationally roughly equal to factoring a composite number of about the size of p.

  • 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 send Encrypted message using public key in Business Service

    Hi,
    I have one public key (abc.cer) which is given by provider. I have to send encrypted message to Provider using public key. How to achieve it in OSB??
    Thanx
    Edited by: Vinit Ahuja on Jun 16, 2011 3:17 AM

    These are the steps needed to accomplish this:
    1. Import the public certificate in the TrustStore of the OSB Weblogic Server.
    2. Export the public certificate in PEM format. (This will be needed to embed in the custom ws policy)
    3. Create a custom WS policy, with the necessary encryption configuration information. I have placed a sample WS - Policy that I have used @ http://dl.dropbox.com/u/19901533/Sample_Custom_WSPolicy_Encryption.doc for your reference.
    Use a unique value for the wsu:Id in the policy.
    4. Apply this custom policy on the business service in the Request section (assuming you only need to encrypt the request fields)
    5. Activate the changes and then test the business service. You can enable tracing on the BS to validate the encrypted content in the logs.
    Hope this helps.
    Thanks,
    Patrick

  • How to renewal SSO public key certificate ??

    hiiiiii
    How to renewal SSO public key certificate....

    Hello,
    You should replace the existing certificate before it expires as per the link provided below.
    http://help.sap.com/saphelp_nw04s/helpdata/en/5c/b7d53ae8ab9248e10000000a114084/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/59/6b653a0c52425fe10000000a114084/frameset.htm
    Thanks,
    Siva Kumar

  • How Sign Message with Certificate (public key)?

    Hi, I need to to send Sign xml message by Certificate file (public key) and read sign message
    so how can i do it ??
    and i should have 2 public key ?? or what ??
    please help :)
    Thanks

    ejp has answered your question, but it seems you did not understand. This forum is not a good place to learn about public key cryptography and message encryption. You should already understand these fundamentals before asking questions here. This forum is about how to implement these crypto operations in the Java programming language. If you are cheap or poor, you can try googling for the more information; wikipedia is good starting point also. If you can afford it, I recommend you buy Practical Cryptography_ by Schneier.

  • How can I hardcode the public key into my coding?

    Hi! I need to hardcode the public key into my program so can someone tell me how can i do it.
    Purpose:-
    I am trying to create a license file( signature file) and the public key in my product.

    Hi! Thank for your reply.
    I dont understand, but anywhere i get the solution already.
    Thanks.
    byte[] pubKey = pub.getEncoded();
                    String hexPubKey = toHexString(pubKey);
                    FileOutputStream pubKeyfos = new FileOutputStream("suepubk");
                    PrintWriter pwPubKey = new PrintWriter(pubKeyfos);
                    pwPubKey.write("PublicKey="+hexPubKey);
                    pwPubKey.close();the following method i got it from internet. I forget the link.
    private static String toHexString(byte[] block) {
            StringBuffer buf = new StringBuffer();
            int len = block.length;
            for (int i = 0; i < len; i++) {
                 byte2hex(block, buf);
    //if (i < len-1) {
    // buf.append(":");
    return buf.toString();

  • How to reconstruct same EC public key

    Hello
    I need to reconstruct EC public key from certificate.
    I have these information as:
    x = 66:6d:59:b1:fb:53:c1:c9:98:c1:2c:71:73:1d:3a:36:a3:7c:d9:95:
    y = ca:de:ee:96:c1:56:c8:d7:c7:85:2b:39:b5:fe:fd:1f:a3:ce:18:c7
    secp160r2
    How can I create ECParameterSpec object from information secp160r2 ?
    Because for creating of ECPublicSpec are necessary to have knowledge of ECPoint and ECParameterSpec objects.
    Can somebody help me resolve this problem ?
    I want to achieve

    I found this sollution:
    ECPoint tempPoint = new ECPoint(
    new BigInteger("666d59b1fb53c1c998c12c71731d3a36a37cd995", 16),
    new BigInteger("cadeee96c156c8d7c7852b39b5fefd1fa3ce18c7", 16));
    org.bouncycastle.jce.spec.ECNamedCurveParameterSpec params =
    ECNamedCurveTable.getParameterSpec("secp160r2");
    org.bouncycastle.jce.spec.ECNamedCurveSpec xxx = new ECNamedCurveSpec(
    params.getName(), params.getCurve(), params.getG(), params.getN(),
    params.getH());
    ECPublicKeySpec spec = new ECPublicKeySpec(tempPoint,xxx);
    PublicKey pub2 = keyFactory.generatePublic(spec);
    byte[] encPub = pub2.getEncoded();
    FileOutputStream pubfos = new FileOutputStream("pub2.key");
    pubfos.write(encPub);
    pubfos.close();

  • How encrypt msg with Public Key ?

    I want to encrypt my Session Key with the public key of the recipient but how can I do ?
    I know how to encrypt with the Secret Key but not with the Public Key.
    Thanks for response
    Nicolas

    It depends on the cryptosystem of which the public key you are having.
    If it is of RSA then you have to get the cipher of RSA and pass the session key bytes as input to it.

  • 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 to check the expired date of a public key stored in my keyStore

    Hello,
    I would like to know if there is any possibility to check the expiration date of a public key which is present in my keystore.
    I did read the help of keytool but did not found any explanation about that.
    Thanks in advance for your answers.
    Alain.
    Message was edited by:
    Philipina

    Public key doesn't have an expiration date. Certificate has. Run keytool -list -v and you can read something looks like:
    Valid from: ... until: ...

Maybe you are looking for

  • Can I change Game Center account that is linked to clash of clans

    HI so when I first got the game Clash Of Clans i was just messing around with it and linked it to my parents game center/iTunes account unknowingly. Well now that I have actually gotten to like the game and such I want to like it to my own iTunes/Gam

  • Lenovo Wifi Replacement

    I recently got my T500 with a very poor signal wifi, Thinkpad BGN, a Realtek chipset. I would like to replace my Wifi card with either the Intel Wifi Link 5100 or 5300. However, I read somewhere that Lenovo specfically "whitelist" their wifi cards to

  • N86 messaging screen freeze

    Hi, Got this new from Nokia less then a week ago and wasn't texting much - more calling and getting use to Symbian. But the few txts I did do were fine. NOW whenever I text and use the space key, which is inevitable, the screen freezes completely. I

  • Firefox cannot download any Flash content using Mac OS Lion

    I am running Mac OS Lion (10.7) and FF 4.01 and 5 (on another Mac). I have both Flash & Video Download and Flash Video Downloader - neither works. It downloads a file showing nothing by gibberish (code).

  • How do i update creative cloud manager application on windows 7?

    or know if i have the latest version? premiere cc and AME cc crash when i queue from premiere to AME. heard i'm suppose to update the cc manager app i have windows 7