How to indetify key pair in Java?

Hello
I need only to know if some private and public key generating one key pair.
I don't want to try it through encrypt/decrypt process and checking data.
Thanks

I have some private key and some public key and I need to detect if private key belongs to some public key. It shouldn't be possible to get into such a state in the first place. Key pairs should be stored in such a way that they are always together, e.g. in a java.security.KeyStore or an HSM, most probably associated with a Certificate.
If true, then I can encrypt data by one of them and correctly decrypt by second.You can encrypt with the public key and decrypt with the private key.
If false ,I will got incorrect data after decryption.No you won't, you'll get an exception.

Similar Messages

  • How to generate key pair using java ?(its urgent)

    We r working on java card. For security purpose I want a Key pair.
    If anyone is able to uide me by giving me a small code or algorithm i am very thankful.
    Its an urgent !!!!
    Plz inform me if any relative information u r having.

    import java.security.KeyPairGenerator;
    import java.security.KeyPair;
    import java.security.PrivateKey;
    import java.security.PublicKey;
    import java.security.SecureRandom;
    import java.security.KeyFactory;
    import java.security.spec.PKCS8EncodedKeySpec;
    import java.security.spec.X509EncodedKeySpec;
    import java.io.FileOutputStream;
    import java.io.FileInputStream;
    public class ParClaves {
         public KeyPairGenerator keyPairGenerator;
         public KeyPair keyPair;
         public PrivateKey privateKey;
         public PublicKey publicKey;
         public String algoritmo = "DSA"; // DSA o RSA
         public String proveedor = null;
         public int keysize = 1024;
         public SecureRandom random = null;
         public void guardarClaves(String fichClavePublica, String fichClavePrivada) throws Exception {
              byte[] key = this.publicKey.getEncoded();
              FileOutputStream keyfos = new FileOutputStream(fichClavePublica);
              keyfos.write(key);
              keyfos.close();               
              key = this.privateKey.getEncoded();
              keyfos = new FileOutputStream(fichClavePrivada);
              keyfos.write(key);
              keyfos.close();               
         } // fin de guardarClaves
         public void guardarClaves(String fichClavePublica, String fichClavePrivada, KeyPair keyPair) throws Exception {
              byte[] key = keyPair.getPublic().getEncoded();
              FileOutputStream keyfos = new FileOutputStream(fichClavePublica);
              keyfos.write(key);
              keyfos.close();               
              key = keyPair.getPrivate().getEncoded();
              keyfos = new FileOutputStream(fichClavePrivada);
              keyfos.write(key);
              keyfos.close();               
         } // fin de guardarClaves     
         public KeyPair recuperarClaves(String fichClavePublica, String fichClavePrivada) throws Exception {
              return new KeyPair(recuperarClavePublica(fichClavePublica), recuperarClavePrivada(fichClavePrivada));
         } // fin de recuperarClaves
         public PublicKey recuperarClavePublica(String fichClavePublica) throws Exception {
    // PENDIENTE: seguramente, para que esto fuera v�lido, habr�a que proporcionar el Proveedor ?�
    // probar generando clavePublica con otro proveedor distinto de SUN
              FileInputStream fis = new FileInputStream(fichClavePublica);
              byte[] encKey = new byte[fis.available()];
              fis.read(encKey);
              fis.close();
              KeyFactory keyFactory = null;
              try {
                   keyFactory = KeyFactory.getInstance("DSA");
              } catch (Exception e) {
                   keyFactory = KeyFactory.getInstance("RSA");
              } // fin del try
              X509EncodedKeySpec pubKeySpecX509 = new X509EncodedKeySpec(encKey);
              PublicKey publicKey = keyFactory.generatePublic(pubKeySpecX509);
              return publicKey;
         } // fin de recuperarClavePublica
         public PrivateKey recuperarClavePrivada(String fichClavePrivada) throws Exception {
    // PENDIENTE: seguramente, para que esto fuera v�lido, habr�a que proporcionar el Proveedor ?�
    // probar generando clavePrivada con otro proveedor distinto de SUN
              FileInputStream fis = new FileInputStream(fichClavePrivada);
              byte[] encKey = new byte[fis.available()];
              fis.read(encKey);
              fis.close();
              KeyFactory keyFactory = null;
              try {
                   keyFactory = KeyFactory.getInstance("DSA");
              } catch (Exception e) {
                   keyFactory = KeyFactory.getInstance("RSA");
              } // fin del try
              PKCS8EncodedKeySpec privKeySpecPKCS8 = new PKCS8EncodedKeySpec(encKey);
              PrivateKey privateKey = keyFactory.generatePrivate(privKeySpecPKCS8);
              return privateKey;
         } // fin de recuperarClavePrivada
         public KeyPair generarClaves() throws Exception {
              if (this.proveedor == null) {
                   this.keyPairGenerator = KeyPairGenerator.getInstance(this.algoritmo);
                   this.proveedor = this.keyPairGenerator.getProvider().getName();
              } else {
                   this.keyPairGenerator = KeyPairGenerator.getInstance(this.algoritmo, this.proveedor);
              } // fin del if
              if (this.random == null) {
                   this.keyPairGenerator.initialize(this.keysize);
              } else {
                   this.keyPairGenerator.initialize(this.keysize, this.random);
              } // fin del if
              this.keyPair = this.keyPairGenerator.generateKeyPair();
              this.privateKey = this.keyPair.getPrivate();
              this.publicKey = this.keyPair.getPublic();
              return this.keyPair;
         } // fin de generarClaves
         public KeyPair generarClaves(SecureRandom random) throws Exception {
              this.random = random;
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(int keysize) throws Exception {
              this.keysize = keysize;
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(int keysize, SecureRandom random) throws Exception {
              this.keysize = keysize;
              this.random = random;          
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmoOproveedor) throws Exception {
              decidir(algoritmoOproveedor);
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmoOproveedor, SecureRandom random) throws Exception {
              decidir(algoritmoOproveedor);
              this.random = random;          
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmoOproveedor, int keysize) throws Exception {
              decidir(algoritmoOproveedor);
              this.keysize = keysize;          
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmoOproveedor, int keysize, SecureRandom random) throws Exception {
              decidir(algoritmoOproveedor);
              this.keysize = keysize;          
              this.random = random;                    
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmo, String proveedor) throws Exception {
              this.algoritmo = algoritmo;          
              this.proveedor = proveedor;                    
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmo, String proveedor, SecureRandom random) throws Exception {
              this.algoritmo = algoritmo;          
              this.proveedor = proveedor;
              this.random = random;                              
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmo, String proveedor, int keysize) throws Exception {
              this.algoritmo = algoritmo;          
              this.proveedor = proveedor;
              this.keysize = keysize;                              
              return generarClaves();
         } // fin de generarClaves
         public KeyPair generarClaves(String algoritmo, String proveedor, int keysize, SecureRandom random) throws Exception {
              this.algoritmo = algoritmo;          
              this.proveedor = proveedor;
              this.keysize = keysize;
              this.random = random;          
              return generarClaves();
         } // fin de generarClaves
         public String getInformacion() {
              StringBuffer sb = new StringBuffer();
              sb.append("Algoritmo: " + this.algoritmo + "\n");
              sb.append("Proveedor: " + this.proveedor + "\n");
              sb.append("Keysize: " + this.keysize + "\n");
              return sb.toString();
         } // fin de getInformacion
         public boolean esAlgoritmoValido(String algoritmo) {
              try {
                   KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(algoritmo);
                   return true;
              } catch (Exception e) {
                   return false;
              } // fin del try
         } // fin de esAlgoritmoValido
         private void decidir(String algoritmoOproveedor) {
              if (esAlgoritmoValido(algoritmoOproveedor)) {
                   this.algoritmo = algoritmoOproveedor;
              } else {
                   this.proveedor = algoritmoOproveedor;
              } // fin del if
         } // fin de decidir
    } // fin de ParClaves

  • Trying to generate secure rpc key pairs with java

    I see a couple of different classes that will generate public private key pairs in various algorithms for me but it doesn't appear that I can supply a pass phrase to use with these.
    I want to write java code that will create a NIS+ secureRPC key pair for me.
    thanks.

    See now this is a really good question. I don't have an answer, but I really like seeing these types of questions here

  • How to recover key pair from certificate

    Hello,
    I am trying to sign my MIDlet. I have followed the instruction below to create key pair and obtain a valid certificate from GeoTrust
    http://java.sun.com/j2me/docs/wtk2.2/docs/UserGuide-html/security.html
    Unfortunately, I deleted the key pairs which I used to create the certificate signing request. Is there anyway I can recover from that? Can I import the key pair from the certificate file? Do I really need the original key pair or I can generate another one?
    Please help
    Thanks
    ben

    Hello,
    I am trying to sign my MIDlet. I have followed the instruction below to create key pair and obtain a valid certificate from GeoTrust
    http://java.sun.com/j2me/docs/wtk2.2/docs/UserGuide-html/security.html
    Unfortunately, I deleted the key pairs which I used to create the certificate signing request. Is there anyway I can recover from that? Can I import the key pair from the certificate file? Do I really need the original key pair or I can generate another one?
    Please help
    Thanks
    ben

  • SSL: How to use the same key pair for ABAP & JAVA?

    Hello,
    I want to setup an XI (3.0 on Netweaver04)installation in the way, that ABAP AS and JAVA AS use the same key pair for SSL. My problem is to define the same private key on ABAP and JAVA. With the JAVA Administrator I am able to define or import a private key. But I could not find a possibility in ABAP to manage private keys in order to use the same on as in JAVA. What is the procedure for this?
    Thanks and Regards,
    Frank Tottleben

    Hello,
    I want to setup an XI (3.0 on Netweaver04)installation in the way, that ABAP AS and JAVA AS use the same key pair for SSL. My problem is to define the same private key on ABAP and JAVA. With the JAVA Administrator I am able to define or import a private key. But I could not find a possibility in ABAP to manage private keys in order to use the same on as in JAVA. What is the procedure for this?
    Thanks and Regards,
    Frank Tottleben

  • Web Server 6.1 - How recovery Key Pair File Password

    I have installed Sun Web Sever 6.1, i am initialized Trust Database, then I generate Request a Certificate for verisign, then verisign send me the Certificate but when i tray install the certificate he say me invalid password, I dont remenber the Key Pair File Password who can recory Key Pair File Password?
    Please help me!

    Assuming that the security libraries are working the way they're supposed to, the password is not recoverable.
    Your best option, other than trying really hard to remember your password, is to delete the certificate and key databases and start over.

  • I need help with Creating Key Pairs

    Hello,
    I need help with Creating Key Pairs, I generate key pais with aba provider, but the keys generated are not base 64.
    the class is :
    import java.io.*;
    import java.math.BigInteger;
    import java.security.*;
    import java.security.spec.*;
    import java.security.interfaces.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    import au.net.aba.crypto.provider.ABAProvider;
    class CreateKeyPairs {
    private static KeyPair keyPair;
    private static KeyPairGenerator pairGenerator;
    private static PrivateKey privateKey;
    private static PublicKey publicKey;
    public static void main(String[] args) throws Exception {
    if (args.length != 2) {
    System.out.println("Usage: java CreateKeyParis public_key_file_name privete_key_file_name");
    return;
    createKeys();
    saveKey(args[0],publicKey);
    saveKey(args[1],privateKey);
    private static void createKeys() throws Exception {
    Security.addProvider(new ABAProvider());
    pairGenerator = KeyPairGenerator.getInstance("RSA","ABA");
    pairGenerator.initialize(1024, new SecureRandom());
    keyPair = pairGenerator.generateKeyPair();
    privateKey = keyPair.getPrivate();
    publicKey = keyPair.getPublic();
    private synchronized static void saveKey(String filename,PrivateKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream(new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    private synchronized static void saveKey(String filename,PublicKey key) throws Exception {
    ObjectOutputStream out= new ObjectOutputStream( new FileOutputStream(filename));
    out.writeObject(key);
    out.close();
    the public key is:
    �� sr com.sun.rsajca.JSA_RSAPublicKeyrC��� xr com.sun.rsajca.JS_PublicKey~5< ~��% L thePublicKeyt Lcom/sun/rsasign/p;xpsr com.sun.rsasign.anm����9�[ [ at [B[ bq ~ xr com.sun.rsasign.p��(!g�� L at Ljava/lang/String;[ bt [Ljava/lang/String;xr com.sun.rsasign.c�"dyU�|  xpt Javaur [Ljava.lang.String;��V��{G  xp   q ~ ur [B���T�  xp   ��ccR}o���[!#I����lo������
    ����^"`8�|���Z>������&
    d ����"B��
    ^5���a����jw9�����D���D�)�*3/h��7�|��I�d�$�4f�8_�|���yuq ~
    How i can generated the key pairs in base 64 or binary????
    Thanxs for help me
    Luis Navarro Nu�ez
    Santiago.
    Chile.
    South America.

    I don't use ABA but BouncyCastle
    this could help you :
    try
    java.security.Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    java.security.KeyPairGenerator kg = java.security.KeyPairGenerator.getInstance("RSA","BC");
    java.security.KeyPair kp = kg.generateKeyPair();
    java.security.Key pub = kp.getPublic();
    java.security.Key pri = kp.getPrivate();
    System.out.println("pub: " + pub);
    System.out.println("pri: " + pri);
    byte[] pub_e = pub.getEncoded();
    byte[] pri_e = pri.getEncoded();
    java.io.PrintWriter o;
    java.io.DataInputStream i;
    java.io.File f;
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pub64"));
    o.println(new sun.misc.BASE64Encoder().encode(pub_e));
    o.close();
    o = new java.io.PrintWriter(new java.io.FileOutputStream("d:/pri64"));
    o.println(new sun.misc.BASE64Encoder().encode(pri_e));
    o.close();
    java.io.BufferedReader br = new java.io.BufferedReader(new java.io.FileReader("d:/pub64"));
    StringBuffer keyBase64 = new StringBuffer();
    String line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] pubBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    br = new java.io.BufferedReader(new java.io.FileReader("d:/pri64"));
    keyBase64 = new StringBuffer();
    line = br.readLine ();
    while(line != null)
    keyBase64.append (line);
    line = br.readLine ();
    byte [] priBytes = new sun.misc.BASE64Decoder().decodeBuffer(keyBase64.toString ());
    java.security.KeyFactory kf = java.security.KeyFactory.getInstance("RSA","BC");
    java.security.Key pubKey = kf.generatePublic(new java.security.spec.X509EncodedKeySpec(pubBytes));
    System.out.println("pub: " + pubKey);
    java.security.Key priKey = kf.generatePrivate(new java.security.spec.PKCS8EncodedKeySpec(priBytes));
    System.out.println("pri: " + priKey);
    catch(Exception e)
    e.printStackTrace ();
    }

  • Is a Public/Private Key Pair possible in SAP?

    I have a web service that I would like to run as part of a nightly script. I currently use username/password authentication, but it is not acceptable to have them hard coded, due to Sarbanes-Oxley rules. SAP's site claims to support authentication with x.509 certificates, but is unclear on the implementation details. How could I go about setting up and using a public/private key pair in SAP?

    Not really a portal question, and maybe you'll get a better result in a security forum...
    However, briefly, yes, the AS Java supports X509 certificates as an authentication mechansm. You need to use Visual Admin to generate a server side certificate, then you need the client side to register its own X509 certificate and then in the Java user admin you need to associate the client certificate with a known user. Now when the client executes the web service call it can pass the certificate and the AS Java will back translate the certificate to a real username.

  • PKCS#11 provider - ECDSA key pair generation on token

    Hello,
    I want to generate ECDSA key pair on HSM (nCipher's netHSM) using SunPKCS11 provider and Java 6.
    After generation for all supported curve names (e.g. secp256r1) I try to call getEncoding method from PublicKey object (keyPair.getPublic().getEncoded()) and
    I get RuntimeException
    caused by java.io.IOException: "Point does not match field size"
    at sun.security.ec.ECParameters.decodePoint(ECParameters.java:75)
    at sun.security.pkcs11.P11ECKeyFactory.decodePoint(P11ECKeyFactory.java:61)
    at sun.security.pkcs11.P11Key$P11ECPublicKey.fetchValues(P11Key.java:1002)
    Keys are accessible on HSM.
    Everything is well configured and works fine with RSA keys.
    Using IAIK PKCS#11 provider I got proper values. Is it any bug in SunPKCS11 provider?
    Regards,
    MarcinP

    I recently had a problem with ECDSA and the PKCS#11 library of nCipher. Here's info from one of their engineers about the PKCS11 library:
    "There are two separate issues - one is that our current pkcs11
    release doesn't support ECDSA signature with SHA-2 hashes
    (the v11.00 firmware adds support for it, but the main release version of
    the pkcs11 library hasn't been updated to take advantage of it yet).
    There is a hotfix version that does support SHA-2 hashes with some
    restrictions, talk to [email protected] for details, and V11.10
    should be out soon and have that merged in.
    But the issue with setting CKA_SIGN is that our underlying HSM API
    allows elliptic curve keys to be either key exchange (ECDH) or
    signature (ECDSA) keys, but not both at one.
    At the PKCS #11 level, if you specify CKA_DERIVE=true and let
    CKA_SIGN default, it will default to false, and vice versa.
    If you specify both CKA_DERIVE=true and CKA_SIGN=true, then we
    return CKR_TEMPLATE_INCONSISTENT because we can't do both with
    the same key. (However, the tests using C_GetMechanismInfo will
    show that we can do both mechanisms, because we can - so long
    as you use different keys, even though they have the same PKCS#11
    type.)
    I can't comment on when or how that will be changed."
    I was using the PKCS#11 library through NSS when I ran into the problem, but I imagine Java would run into similar problems also using the PKCS#11 library. I was able to generate keypairs but not create a CSR (which required making a signature, which required SHA-2).
    Can you just use the java classes to speak to the netHSM? I've never directly written code to do so myself, but I have used Corestreet's OCSP product that uses the java classes to speak to the nCipher HSMs (though not using EC). It might work better than going through the PKCS#11 layer. There should be a java directory under NFAST_HOME that contains some jars.
    Please post back if you figure anything out as I'll probably be playing with this stuff myself soon.
    Dave

  • Generating key pair on PKCS#11token and save it there

    Hello,
    again i'm completely lost in this PKCS11 jungle.
    What i want to do:
    Generating key pair on crypto pkcs11 token and store it there.
    In the moment i've tried eg:
    sun.security.pkcs11.SunPKCS11 p = new sun.security.pkcs11.SunPKCS11(configName);
    Security.addProvider(p);
    Builder builder = KeyStore.Builder.newInstance("PKCS11", p, new KeyStore.CallbackHandlerProtection(new UserInputDialog(new JDialog(),"test","test")));
    KeyStore ks = builder.getKeyStore();
    ks.load(null,null);
    KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA", p);
    gen.initialize(1024);
    KeyPair kp = gen.generateKeyPair();
               Here access to token works. The callback PIN dialog comes up and i can login.
    But i'm not sure whether the key are generated on this PKCS11. And they are not stored there.
    How i can generate keys are stored there.
    (like with keytool -genkeys ). In keytool case a certificate is stored.
    ... every little hint, also to some documentation i've not seen, is very welcome ...
    Thank You !
    Regards
    Thomas
    .

    First, you need to get a KeyStore representation of the PKCS#11 token with code similar to this, I'm using NSS as the PKCS#11 token in this example:
    Provider nss = new sun.security.pkcs11.SunPKCS11(configFile);
    Security.insertProviderAt(nss, 1);  //you may not want it at highest priority
    KeyStore ks = KeyStore.getInstance("PKCS11", nss);
    ks.load(null, password);From the testing I've done in the past with various tokens, when you generate an asymmetric keypair (e.g. RSA like you are) specifying the PKCS11 provider, it creates it right on the token automatically and code like below is not needed.
    To store the key in the keystore, use code similar to this, I'm using NSS again and storing a symmetric key:
    KeyGenerator kg = KeyGenerator.getInstance("DESede",nss);
    SecretKey tripleDesKey = kg.generateKey();
    KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(tripleDesKey);
    ks.setEntry(randAlias, skEntry, new KeyStore.PasswordProtection(password));

  • How to detect key board event

    HI,
    How to detect keyboard event (Like CTRL key press shift key press) in Swing�any can any body suggest classes and interface for that�.
    Thanks

    [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to use Key Bindings

  • Can someone help me? Why i can not build RSA key pair

    i download the java_card_kit-2_2_01-win-gl.zip from sun's web site
    and i use the keypair class to build a RSA key pair
    but it always throws NO_SUCH_ALGORITHM excption.
    how can i build a key pair

    This has been covered a million times. There isn't any crypto implementation with Sun's kit. This is mentioned in the documentation.

  • How to send key for unicode characters?

    Hi Gurus,
    I want to send an unicode character to screen, but can't figure out a way to do so. In java, we can send a virtual key code using java.awt.event.KeyEvent. But how can I send a unicode character to the screen? Must I implement an input method? how to do that....?
    Anyone can give me some ideas?
    Thanks,
    Perky

    Found tha answer myself: set System.useCodePage to false

  • How to Commit table by writting Java code in Managed Bean?

    Hi,
    Can anyone suggest me how to Commit table by writing Java code in Managed Bean?.
    I want to commit table manually after modifying in UI.
    Please suggest me guys.
    Thanks,
    Ramit Mathur

    Hi Friend Copy this two java files with same package of your bean package.
    1,*ADFUtils.java*
    package org.calwin.common.view.utils;(Your package name)
    import java.util.ArrayList;
    import java.util.List;
    import javax.el.ELContext;
    import javax.el.ExpressionFactory;
    import javax.el.MethodExpression;
    import javax.el.ValueExpression;
    import javax.faces.context.FacesContext;
    import javax.faces.model.SelectItem;
    import oracle.adf.model.BindingContext;
    import oracle.adf.model.binding.DCBindingContainer;
    import oracle.adf.model.binding.DCIteratorBinding;
    import oracle.adf.model.binding.DCParameter;
    import oracle.adf.share.logging.ADFLogger;
    import oracle.binding.AttributeBinding;
    import oracle.binding.BindingContainer;
    import oracle.binding.ControlBinding;
    import oracle.binding.OperationBinding;
    import oracle.jbo.ApplicationModule;
    import oracle.jbo.Key;
    import oracle.jbo.Row;
    import oracle.jbo.uicli.binding.JUCtrlValueBinding;
    * A series of convenience functions for dealing with ADF Bindings.
    * Note: Updated for JDeveloper 11
    * @author Duncan Mills
    * @author Steve Muench
    * $Id: ADFUtils.java 2513 2007-09-20 20:39:13Z ralsmith $.
    public class ADFUtils
    public static final ADFLogger _LOGGER = ADFLogger.createADFLogger(ADFUtils.class);
    * Get application module for an application module data control by name.
    * @param pName application module data control name
    * @return ApplicationModule
    public static ApplicationModule getApplicationModuleForDataControl(String pName)
    return (ApplicationModule) JSFUtils.resolveExpression("#{data." + pName + ".dataProvider}");
    * A convenience method for getting the value of a bound attribute in the
    * current page context programatically.
    * @param pAttributeName of the bound value in the pageDef
    * @return value of the attribute
    public static Object getBoundAttributeValue(String pAttributeName)
    return findControlBinding(pAttributeName).getInputValue();
    * A convenience method for setting the value of a bound attribute in the
    * context of the current page.
    * @param pAttributeName of the bound value in the pageDef
    * @param pValue to set
    public static void setBoundAttributeValue(String pAttributeName, Object pValue)
    findControlBinding(pAttributeName).setInputValue(pValue);
    * Returns the evaluated value of a pageDef parameter.
    * @param pPageDefName reference to the page definition file of the page with the parameter
    * @param pParameterName name of the pagedef parameter
    * @return evaluated value of the parameter as a String
    public static Object getPageDefParameterValue(String pPageDefName, String pParameterName)
    BindingContainer bindings = findBindingContainer(pPageDefName);
    DCParameter param = ((DCBindingContainer) bindings).findParameter(pParameterName);
    return param.getValue();
    * Convenience method to find a DCControlBinding as an AttributeBinding
    * to get able to then call getInputValue() or setInputValue() on it.
    * @param pBindingContainer binding container
    * @param pAttributeName name of the attribute binding.
    * @return the control value binding with the name passed in.
    public static AttributeBinding findControlBinding(BindingContainer pBindingContainer, String pAttributeName)
    if (pAttributeName != null)
    if (pBindingContainer != null)
    ControlBinding ctrlBinding = pBindingContainer.getControlBinding(pAttributeName);
    if (ctrlBinding instanceof AttributeBinding)
    return (AttributeBinding) ctrlBinding;
    return null;
    * Convenience method to find a DCControlBinding as a JUCtrlValueBinding
    * to get able to then call getInputValue() or setInputValue() on it.
    * @param pAttributeName name of the attribute binding.
    * @return the control value binding with the name passed in.
    public static AttributeBinding findControlBinding(String pAttributeName)
    return findControlBinding(getBindingContainer(), pAttributeName);
    * Return the current page's binding container.
    * @return the current page's binding container
    public static BindingContainer getBindingContainer()
    return (BindingContainer) JSFUtils.resolveExpression("#{bindings}");
    * Return the Binding Container as a DCBindingContainer.
    * @return current binding container as a DCBindingContainer
    public static DCBindingContainer getDCBindingContainer()
    return (DCBindingContainer) getBindingContainer();
    * Get List of ADF Faces SelectItem for an iterator binding.
    * Uses the value of the 'valueAttrName' attribute as the key for
    * the SelectItem key.
    * @param pIteratorName ADF iterator binding name
    * @param pValueAttrName name of the value attribute to use
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @return ADF Faces SelectItem for an iterator binding
    public static List<SelectItem> selectItemsForIterator(String pIteratorName, String pValueAttrName, String pDisplayAttrName)
    return selectItemsForIterator(findIterator(pIteratorName), pValueAttrName, pDisplayAttrName);
    * Get List of ADF Faces SelectItem for an iterator binding with description.
    * Uses the value of the 'valueAttrName' attribute as the key for
    * the SelectItem key.
    * @param pIteratorName ADF iterator binding name
    * @param pValueAttrName name of the value attribute to use
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @param pDescriptionAttrName name of the attribute to use for description
    * @return ADF Faces SelectItem for an iterator binding with description
    public static List<SelectItem> selectItemsForIterator(String pIteratorName, String pValueAttrName, String pDisplayAttrName, String pDescriptionAttrName)
    return selectItemsForIterator(findIterator(pIteratorName), pValueAttrName, pDisplayAttrName, pDescriptionAttrName);
    * Get List of attribute values for an iterator.
    * @param pIteratorName ADF iterator binding name
    * @param pValueAttrName value attribute to use
    * @return List of attribute values for an iterator
    public static List attributeListForIterator(String pIteratorName, String pValueAttrName)
    return attributeListForIterator(findIterator(pIteratorName), pValueAttrName);
    * Get List of Key objects for rows in an iterator.
    * @param pIteratorName iterabot binding name
    * @return List of Key objects for rows
    public static List<Key> keyListForIterator(String pIteratorName)
    return keyListForIterator(findIterator(pIteratorName));
    * Get List of Key objects for rows in an iterator.
    * @param pIterator iterator binding
    * @return List of Key objects for rows
    public static List<Key> keyListForIterator(DCIteratorBinding pIterator)
    List<Key> attributeList = new ArrayList<Key>();
    for (Row r: pIterator.getAllRowsInRange())
    attributeList.add(r.getKey());
    return attributeList;
    * Get List of Key objects for rows in an iterator using key attribute.
    * @param pIteratorName iterator binding name
    * @param pKeyAttrName name of key attribute to use
    * @return List of Key objects for rows
    public static List<Key> keyAttrListForIterator(String pIteratorName, String pKeyAttrName)
    return keyAttrListForIterator(findIterator(pIteratorName), pKeyAttrName);
    * Get List of Key objects for rows in an iterator using key attribute.
    * @param pIterator iterator binding
    * @param pKeyAttrName name of key attribute to use
    * @return List of Key objects for rows
    public static List<Key> keyAttrListForIterator(DCIteratorBinding pIterator, String pKeyAttrName)
    List<Key> attributeList = new ArrayList<Key>();
    for (Row r: pIterator.getAllRowsInRange())
    attributeList.add(new Key(new Object[]
    { r.getAttribute(pKeyAttrName) }));
    return attributeList;
    * Get a List of attribute values for an iterator.
    * @param pIterator iterator binding
    * @param pValueAttrName name of value attribute to use
    * @return List of attribute values
    public static List attributeListForIterator(DCIteratorBinding pIterator, String pValueAttrName)
    List attributeList = new ArrayList();
    for (Row r: pIterator.getAllRowsInRange())
    attributeList.add(r.getAttribute(pValueAttrName));
    return attributeList;
    * Find an iterator binding in the current binding container by name.
    * @param pName iterator binding name
    * @return iterator binding
    public static DCIteratorBinding findIterator(String pName)
    DCIteratorBinding iter = getDCBindingContainer().findIteratorBinding(pName);
    if (iter == null)
    throw new RuntimeException("Iterator '" + pName + "' not found");
    return iter;
    * @param pBindingContainer
    * @param pIterator
    * @return
    public static DCIteratorBinding findIterator(String pBindingContainer, String pIterator)
    DCBindingContainer bindings = (DCBindingContainer) JSFUtils.resolveExpression("#{" + pBindingContainer + "}");
    if (bindings == null)
    throw new RuntimeException("Binding container '" + pBindingContainer + "' not found");
    DCIteratorBinding iter = bindings.findIteratorBinding(pIterator);
    if (iter == null)
    throw new RuntimeException("Iterator '" + pIterator + "' not found");
    return iter;
    * @param pName
    * @return
    public static JUCtrlValueBinding findCtrlBinding(String pName)
    JUCtrlValueBinding rowBinding = (JUCtrlValueBinding) getDCBindingContainer().findCtrlBinding(pName);
    if (rowBinding == null)
    throw new RuntimeException("CtrlBinding " + pName + "' not found");
    return rowBinding;
    * Find an operation binding in the current binding container by name.
    * @param pName operation binding name
    * @return operation binding
    public static OperationBinding findOperation(String pName)
    OperationBinding op = getDCBindingContainer().getOperationBinding(pName);
    if (op == null)
    throw new RuntimeException("Operation '" + pName + "' not found");
    return op;
    * Find an operation binding in the current binding container by name.
    * @param pBindingContianer binding container name
    * @param pOpName operation binding name
    * @return operation binding
    public static OperationBinding findOperation(String pBindingContianer, String pOpName)
    DCBindingContainer bindings = (DCBindingContainer) JSFUtils.resolveExpression("#{" + pBindingContianer + "}");
    if (bindings == null)
    throw new RuntimeException("Binding container '" + pBindingContianer + "' not found");
    OperationBinding op = bindings.getOperationBinding(pOpName);
    if (op == null)
    throw new RuntimeException("Operation '" + pOpName + "' not found");
    return op;
    * Get List of ADF Faces SelectItem for an iterator binding with description.
    * Uses the value of the 'valueAttrName' attribute as the key for
    * the SelectItem key.
    * @param pIterator ADF iterator binding
    * @param pValueAttrName name of value attribute to use for key
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @param pDescriptionAttrName name of the attribute for description
    * @return ADF Faces SelectItem for an iterator binding with description
    public static List<SelectItem> selectItemsForIterator(DCIteratorBinding pIterator, String pValueAttrName, String pDisplayAttrName, String pDescriptionAttrName)
    List<SelectItem> selectItems = new ArrayList<SelectItem>();
    for (Row r: pIterator.getAllRowsInRange())
    selectItems.add(new SelectItem(r.getAttribute(pValueAttrName), (String) r.getAttribute(pDisplayAttrName), (String) r.getAttribute(pDescriptionAttrName)));
    return selectItems;
    * Get List of ADF Faces SelectItem for an iterator binding.
    * Uses the value of the 'valueAttrName' attribute as the key for
    * the SelectItem key.
    * @param pIterator ADF iterator binding
    * @param pValueAttrName name of value attribute to use for key
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @return ADF Faces SelectItem for an iterator binding
    public static List<SelectItem> selectItemsForIterator(DCIteratorBinding pIterator, String pValueAttrName, String pDisplayAttrName)
    List<SelectItem> selectItems = new ArrayList<SelectItem>();
    for (Row r: pIterator.getAllRowsInRange())
    selectItems.add(new SelectItem(r.getAttribute(pValueAttrName), (String) r.getAttribute(pDisplayAttrName)));
    return selectItems;
    * Get List of ADF Faces SelectItem for an iterator binding.
    * Uses the rowKey of each row as the SelectItem key.
    * @param pIteratorName ADF iterator binding name
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @return ADF Faces SelectItem for an iterator binding
    public static List<SelectItem> selectItemsByKeyForIterator(String pIteratorName, String pDisplayAttrName)
    return selectItemsByKeyForIterator(findIterator(pIteratorName), pDisplayAttrName);
    * Get List of ADF Faces SelectItem for an iterator binding with discription.
    * Uses the rowKey of each row as the SelectItem key.
    * @param pIteratorName ADF iterator binding name
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @param pDescriptionAttrName name of the attribute for description
    * @return ADF Faces SelectItem for an iterator binding with discription
    public static List<SelectItem> selectItemsByKeyForIterator(String pIteratorName, String pDisplayAttrName, String pDescriptionAttrName)
    return selectItemsByKeyForIterator(findIterator(pIteratorName), pDisplayAttrName, pDescriptionAttrName);
    * Get List of ADF Faces SelectItem for an iterator binding with discription.
    * Uses the rowKey of each row as the SelectItem key.
    * @param pIterator ADF iterator binding
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @param pDescriptionAttrName name of the attribute for description
    * @return ADF Faces SelectItem for an iterator binding with discription
    public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding pIterator, String pDisplayAttrName, String pDescriptionAttrName)
    List<SelectItem> selectItems = new ArrayList<SelectItem>();
    for (Row r: pIterator.getAllRowsInRange())
    selectItems.add(new SelectItem(r.getKey(), (String) r.getAttribute(pDisplayAttrName), (String) r.getAttribute(pDescriptionAttrName)));
    return selectItems;
    * Get List of ADF Faces SelectItem for an iterator binding.
    * Uses the rowKey of each row as the SelectItem key.
    * @param pIterator ADF iterator binding
    * @param pDisplayAttrName name of the attribute from iterator rows to display
    * @return List of ADF Faces SelectItem for an iterator binding
    public static List<SelectItem> selectItemsByKeyForIterator(DCIteratorBinding pIterator, String pDisplayAttrName)
    List<SelectItem> selectItems = new ArrayList<SelectItem>();
    for (Row r: pIterator.getAllRowsInRange())
    selectItems.add(new SelectItem(r.getKey(), (String) r.getAttribute(pDisplayAttrName)));
    return selectItems;
    * Find the BindingContainer for a page definition by name.
    * Typically used to refer eagerly to page definition parameters. It is
    * not best practice to reference or set bindings in binding containers
    * that are not the one for the current page.
    * @param pPageDefName name of the page defintion XML file to use
    * @return BindingContainer ref for the named definition
    private static BindingContainer findBindingContainer(String pPageDefName)
    BindingContext bctx = getDCBindingContainer().getBindingContext();
    BindingContainer foundContainer = bctx.findBindingContainer(pPageDefName);
    return foundContainer;
    * @param pOpList
    public static void printOperationBindingExceptions(List pOpList)
    if (pOpList != null && !pOpList.isEmpty())
    for (Object error: pOpList)
    _LOGGER.severe(error.toString());
    * Programmatic invocation of a method that an EL evaluates to.
    * The method must not take any parameters.
    * @param pEl EL of the method to invoke
    * @return Object that the method returns
    public static Object invokeEL(String pEl)
    return invokeEL(pEl, new Class[0], new Object[0]);
    * Programmatic invocation of a method that an EL evaluates to.
    * @param pEl EL of the method to invoke
    * @param pParamTypes Array of Class defining the types of the parameters
    * @param pParams Array of Object defining the values of the parametrs
    * @return Object that the method returns
    public static Object invokeEL(String pEl, Class[] pParamTypes, Object[] pParams)
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    MethodExpression exp = expressionFactory.createMethodExpression(elContext, pEl, Object.class, pParamTypes);
    return exp.invoke(elContext, pParams);
    * Sets the EL Expression with the value.
    * @param pEl EL Expression for which the value to be assigned.
    * @param pVal Value to be assigned.
    public static void setEL(String pEl, Object pVal)
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    ValueExpression exp = expressionFactory.createValueExpression(elContext, pEl, Object.class);
    exp.setValue(elContext, pVal);
    * Evaluates the EL Expression and returns its value.
    * @param pEl Expression to be evaluated.
    * @return Value of the expression as Object.
    public static Object evaluateEL(String pEl)
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
    ValueExpression exp = expressionFactory.createValueExpression(elContext, pEl, Object.class);
    return exp.getValue(elContext);
    }

  • How to export key in smart card to byte array?

    How to export key in smart card to byte array?
    I want to export key to byte array to xor with some data. How can I do?
    I use java card kit 1.2.1 and jdk1.3.1_02
    Thanks

    Can I write like this?
    import javacard.security.*;
    /* in method */
    byte[] keyExoprt = new byte[64];
    Key v = Key.buildKey(KeyBuilder.TYPE_DSA_PRIVATE,KeyBuilder. LENGTH_DSA_512, false);
    short a = DSAPrivateKey.getX(keyExport, KeyBuilder. LENGTH_DSA_512);
    ////////////////////////////////////////////////////////////////////////////////////////

Maybe you are looking for

  • Where is "save as DCS 1.0 or 2.0"

    It seems to me the last time I save a file as a duotone out of Photoshop I just had to convert it to a duotone and go to "save as" and choose DCS 2.0. But, today I am not seeing that option. I feel as though I'm going crazy. What step am I missing?

  • One machine but I tunes says I authorized 4 of my 5 allowed please help

    I have one desktop and one Ipod, I just reinstalled windows now Itunes must think it is a new machine. Can I get my account back to 1 machine and 1 Ipod? I want to be able to use a laptop also but I think this will put me over the top once I plug in

  • Error in Merge statement for Oracle 10gR2

    Hi, When I use the MERGE statement to copy data across a database link (from 10gR2 to 10gR2 database), if I have both an update and insert clause it works fine, but if I omit the insert clause and have just update on its own, I get error "ORA-02064:

  • First Ajax request really slow with Generator

    Doing simple Html panel <-> Generator plugin communication and noticed a strange issue with first Ajax call being much slower than the rest. I.e. in panel javascript the first Ajax call duration is 2000ms+ the first time and then consistently ~5ms ev

  • What will happen when I 'reset network settings'?

    I lost my personal hotspot setting. Just wondering what will happen if I reset. Will my phone automatically reset or will I need passwords, etc?