Unable to store SecretKey in KeyStore

Hi there.
I am trying to store a SecretKey in a KeyStore, and that doesn't work.
I create a secret key, wrap it up in KeyStore.SecretKeyEntry to add it into my key store. Looking at the API for KeyStore class, we have a method setEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam). The second parameter being KeyStore.Entry, it should be accepting any implementation of KeyStore.Entry, which in my case is KeyStore.SecretKeyEntry. At runtime, an exception is thrown saying that non-private keys cannot be stored!
Can someone throw some light on this please.
Following is my source code and the exception that I see.
Thank you.
import java.io.*;
import java.security.*;
import java.security.cert.*;
import javax.crypto.*;
public class KeyStoreManager {
    private static final String PRIVATE_KEY_ALGORITHM_BLOWFISH = "Blowfish";
    private static final String PRIVATE_KEY_ALGORITHM_DSA = "DSA";
    private static final String KEYSTORE_TYPE = "jks";
    private static final String KEYSTORE_FILE = "C:\\keystore.ks";
    private static final String KEYSTORE_PASSWORD = "keystorepassword";
    private static final int PRIVATE_KEY_SIZE_IN_BITS = 448; //56 bytes
    private SecretKey createSecretKey() throws Exception {
        KeyGenerator keyGenerator = null;
        keyGenerator = KeyGenerator.getInstance(PRIVATE_KEY_ALGORITHM_BLOWFISH);
        keyGenerator.init(PRIVATE_KEY_SIZE_IN_BITS);
        return keyGenerator.generateKey();
    private KeyStore getKeyStore(String keyStoreName, char[] password) throws Exception {
        KeyStore keyStore = KeyStore.getInstance(KEYSTORE_TYPE);
        InputStream stream = null;
        keyStore.load(stream, password);
        keyStore.store(new FileOutputStream(keyStoreName), password);
        return keyStore;
    public static void main(String[] args) throws Exception {
        File keyStoreFile = new File(KEYSTORE_FILE);
        if (keyStoreFile.exists() && keyStoreFile.isFile()) {
            keyStoreFile.delete();
        KeyStoreManager ksm = new KeyStoreManager();
        KeyStore keyStore = ksm.getKeyStore(KEYSTORE_FILE, KEYSTORE_PASSWORD.toCharArray());
        SecretKey secretKey = ksm.createSecretKey();
        KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey);
        KeyStore.ProtectionParameter passwordProtection = new KeyStore.PasswordProtection("entrypassword".toCharArray());
        keyStore.setEntry("SecretKeyAlias", secretKeyEntry, passwordProtection);
        System.out.println("Added key into store");
The exception that I see is..._
Exception in thread "main" java.security.KeyStoreException: Cannot store non-PrivateKeys
at sun.security.provider.JavaKeyStore.engineSetKeyEntry(Unknown Source)
at sun.security.provider.JavaKeyStore$JKS.engineSetKeyEntry(Unknown Source)
at java.security.KeyStoreSpi.engineSetEntry(Unknown Source)
at java.security.KeyStore.setEntry(Unknown Source)
at KeyStoreManager.main(KeyStoreManager.java:42)

A 'JKS' keystore can only store private keys and certificates but not secret keys. Blowfish is a symmetric algorithm and uses a secret key so Blowfish keys cannot be stored in a 'JKS' keystore. You could switch to using 'JCEKS' which allows secret keys.

Similar Messages

  • Job submission failed : error occurred while scheduling the job. org.quartz.objectalreadyexistsexception: unable to store job with name

    Experts,
    Please help me out here,Am facing this issue while scheduling a job in BIPublisher.
    job submission failed : error occurred while scheduling the job. org.quartz.objectalreadyexistsexception: unable to store job with name
    Thanks,

    You are probably installing on a hardened machine.
    The "installation guide" says that if you are doing so, you need to create a file named libx11.so.4 and update your LD_LIBRARY_PATH (see http://docs.iplanet.com/docs/manuals/messaging/ims52/ig/unix/overview.htm)but:
    1- the library name is libX11.so.4 and
    2- for jre a common file is not enough, you need to install SUNWxwplt at least. This will install the library on /usr/openwin/lib.
    You can check the results running <server-root>/bin/base/jre/bin/jre
    Hope that helps and sorry about my poor english.

  • Ipod unknown error message 'Unable to store pair record'

    I get this error: "iTunes cannot connect to this iPod touch. An unknown error message 'Unable to store pair record', was received from the device"

    pairing record ?
    http://www.tuaw.com/2008/01/23/a-fix-for-those-pairing-record-missing-errors/

  • Unable to store log data into database through JDBCAppender of Log4j

    I am able to store the log data into the file as well as to display that on console. But unable to store the same into the database. I am not getting any error or warning while execution. The code of log.properties is as below : -
    log4j.rootLogger=ERROR, C, FILE
    log4j.logger.org.firebird=ERROR, C
    log4j.logger.org.firebirdsql=ERROR, C
    log4j.logger.org.apache.joran=ERROR, C
    log4j.logger.org.apache.log4j.joran.action=ERROR, C
    log4j.appender.FILE=org.apache.log4j.FileAppender
    log4j.appender.FILE.file=/log.txt
    log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    log4j.appender.FILE.layout.ConversionPattern=[%d{MMM dd HH:mm:ss}] %-5p (%F:%L) - %m%n
    log4j.logger.org.apache.log4j.jdbcplus.examples=DEBUG, JDBC
    # console appender
    log4j.appender.C=org.apache.log4j.ConsoleAppender
    log4j.appender.C.layout=org.apache.log4j.PatternLayout
    log4j.appender.C.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n
    # JDBC appender using custom handlers, 2a)
    log4j.appender.JDBC=org.apache.log4j.jdbcplus.JDBCAppender
    log4j.appender.JDBC.connector=org.apache.log4j.jdbcplus.examples.MySqlConnectionHandler
    log4j.appender.JDBC.sqlhandler=org.apache.log4j.jdbcplus.examples.SqlHandler
    log4j.appender.JDBC.dbclass=com.mysql.jdbc.Driver
    log4j.appender.JDBC2.url=jdbc:mysql:172.22.15.131/3306:plugins?
    log4j.appender.JDBC2.username=user18
    log4j.appender.JDBC2.password=user18
    log4j.appender.JDBC.buffer=1
    log4j.appender.JDBC.commit=true
    log4j.appender.JDBC.sql=INSERT INTO logtest (id, prio, iprio, cat, thread, msg, layout_msg, throwable, ndc, mdc, mdc2, info,
    addon, the_date, the_time, the_timestamp, created_by) VALUES (@INC@, '@PRIO@', @IPRIO@, '@CAT@', '@THREAD@', '@MSG@',
    '@LAYOUT:1@', '@THROWABLE@', '@NDC@', '@MDC:MyMDC@', '@MDC:MyMDC2@', 'info timestamp: @TIMESTAMP@', '@LAYOUT@', cast
    ('@LAYOUT:3@' as date), cast ('@LAYOUT:4@' as time), cast ('@LAYOUT:3@ @LAYOUT:4@' as timestamp), 'me')
    log4j.appender.JDBC.layout=org.apache.log4j.PatternLayout
    log4j.appender.JDBC.layout.ConversionPattern=%m
    Please help me out.. As I got stuck...

    Hi,
    This might help
    http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
    I think heading about that blog post is wrong. It is solution to import CSV.
    But you can convert your Excels easilly to CSV.
    I think import pure Excel is quite hard, and I have not seen any solutions.
    See this post also
    Importing Excel spreadsheet into Oracle via Apex
    Br,Jari

  • Setup is unable to store configuration data in the LDAP directory

    I am attempting to install the Sun One Directory Server 5.1 on my Windows 2000 machine. At the conclusion of the installation process, I recieve these back to back pop up windows:
    Error:
    Setup is unable to store configuration data in the LDAP directory.
    Error:
    Unable to create administration server configuration.
    Error:
    Could not authenticate ldap connection, "Unknown error".
    Error:
    Unable to set ACI in Configuration Directory Server
    Setup
    Setup's Post-Install mode failed for the Sub Component admin belonging to the component admin. Do you want to continue.
    What am I doing wrong?

    Hi,
    Can you please send me logconv.pl code to [email protected] I am unable to find the file

  • Unable to store sent message on Yahoo server

    When I send an email from Mail ( Lion OS Mail) I am unable to store the sent message on the Yahoo server.
    I have set up my Yahoo email account as a POP account & I do not see the option of “ Store sent message on the server” as in iCloud email.
    The iCloud email is set up as IMAP.
    Any help to solve this problem is appreciated

    Right with POP Sent emails only show on your local computer unless you are using IMAP and even then it is a setting in the mail program and the IMAP server to store all sent emails on the server. With Gmail they are included in the All Mail folder. But Yahoo is different and only if you have a paid Yahoo account do you have access to their IMAP system.
    No way to do that with POP.

  • I got iPhone 5 but unable to store notes on iCloud

    I got new iPhone5 but unable to store nates on iCloud. Contacts data is stored but not my notes in iPhone.

    Unfortunately, when you buy an iPhone second-hand, you will need the owner to first remove it from their iCloud account. There is currently no way to remove it yourself, and you will have to contact the seller manually.
    As for your questions:
    1. You will have to find the owner yourself. if you bought the phone from a second-hand store, try contacting them to see if they have any information about the seller. If you bought it directly, try sending them an email or give them a phone call and ask them to remove it from their iCloud account.
    2. There is nothing you can do to activate it yourself, because it must first be removed from the iCloud account it was registered to.
    Please see this article for more information:
    Find My iPhone Activation Lock: Removing a device from a previous owner’s account
    I wish you the best of luck.

  • ErrorERR-1029 Unable to store session info. session=1027480127369301 item

    Hi,
    Whenever i tried to export or copy the application it getting an error like
         Error     ERR-1029 Unable to store session info. session=1027480127369301 item=40006855470898
    ORA-02091: transaction rolled back ORA-02291: integrity constraint (APEX_040100.WWV_FLOW_STEP_PROCESS_FK) violated - parent key not found
    Please help me out this problem.
    Thanks.
    Apex Version - 4.1
    Database - 11gR2

    hi,
    you can have a look this thread
    ERR-1029 Unable to store session info and APEX_040100.WWV_FLOW_DATA_IDX1
    https://kr.forums.oracle.com/forums/thread.jspa?threadID=498323
    regards,

  • I am unable to store recovery .

    i am unable to store recovery. Its shows might be there some hardware problem please help me

    Please post your full product Number
    http://h10025.www1.hp.com/ewfrf/wc/findModel?cc=us&dlc=en&lc=en
    #2
    Please Do Not post your s/n

  • Why am I unable to store all url password access details in keychain?

    Wht am I unable to store all url password details in keychain?

    thanks kindly for responding
    apologies - my question was ambiguous, and it is not the 'details', so let me explain my problem
    I purchased my new imac a week ago.  I have a number of websites which I have accounts with, and am trying to use Keychain to store my username/password combinations for each of these. 
    The process should work as follows:  when I open up the website, enter a username and password combination and commit to 'login', the iMAC responds with a window asking if the username/password combination should be saved, if I select save then the iMAC stores the username/password combination in Keychain.  When I revisit that website at a later time/date Keychain automatically completes the username/password entries, enabling login.
    This process has succeeded only for some of my websites concerned, and for others my iMAC fails to respond with a window requesting a 'save' or not, hence the username/password is not stored in Keychain (under 'login' 'passwords').
    Hence not all url sites work, and for these I thereafter need to manually insert the username/password to achieve 'login'

  • SecretKey in keystore and on file

    Hi,
    I understand that the SecretKey type is password based encrypted with the password a user inputs.
    1) What algorithm is used for the encryption?
    2) Is there an option not to encrypt the key? enabling access only with a password (math input to embedded password or hash...) ***still using the keystore
    or storing the key in the keystore unprotected (no password at all).
    Thanks.

    800414 wrote:
    I understand that the SecretKey type is password based encrypted with the password a user inputs.Java Keystore are password protected. Obviously this must be done through some form a PBE.
    1) What algorithm is used for the encryption?Why do you think need to know this?
    2) Is there an option not to encrypt the key? enabling access only with a password (math input to embedded password or hash...) ***still using the keystoreI don't really understand what you are asking? Keystores as a whole are password protected and SecretKey and PrivateKey entries are further password protected but Certificates are not.
    or storing the key in the keystore unprotected (no password at all).What would be the point? If you are not going to use password protection then you can just write the bytes of the key to a file.
    It is not obvious to me what you expect as a response to this thread. Maybe if you supplied some context it would be more obvious.

  • Unable to locate oraks.jks keystore

    Hi
    Can anyone help me out to locate oraks.jws keystore which is a default keystore said to be found in <OC4J-HOME>/config but i couldn't find it.
    I need it for implementing security on my web services.
    Plz help.
    Thanks,
    Amardeep

    A 'JKS' keystore can only store private keys and certificates but not secret keys. Blowfish is a symmetric algorithm and uses a secret key so Blowfish keys cannot be stored in a 'JKS' keystore. You could switch to using 'JCEKS' which allows secret keys.

  • Unable to store PDF , XL , Word document into SAP archived tables

    Hi Experts,
    I have created a web interface in WD ABAP which stores the employee's attachement data into sap arcived link.
    For that I have carried out following activities.
    I have Complted customizing for a document type under business object PREL and for this I have reffered following link.
    SASAP Archived Link
    Now I have used file Upload UI element in WDABAP which passes the local file data in Xstring to following function modoules for creating
    an attachment.
    data: it_out type TOADT,
    it_storage type ZDMSSTORAGE.
    CALL FUNCTION 'ARCHIV_CREATE_TABLE'
    EXPORTING
    ar_object = 'HRPDATA' " Object catagory that I have created for file storage under Business Object PREL
    object_id = '10000008'
    sap_object = 'PREL'
    document = filedata
    IMPORTING
    OUTDOC = it_out
    EXCEPTIONS
    error_archiv = 1
    error_communicationtable = 2
    error_connectiontable = 3
    error_kernel = 4
    error_parameter = 5
    error_user_exit = 6
    OTHERS = 7.
    For reading the attached document I am using following FM's
    CALL FUNCTION 'SCMS_AO_TABLE_GET'
    EXPORTING
    MANDT = SY-MANDT
    arc_id = 'Z1'
    doc_id = lv_doc_type"im_doc "'4D5D8445165220C8E10000000A3C082E'
    COMP_ID = 'data'
    IMPORTING
    LENGTH =
    tables
    data = bindata.
    *data: BINARY_TAB type
    CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
    input_length = 10000
    FIRST_LINE = 0
    LAST_LINE = 0
    IMPORTING
    BUFFER = V_XSTRING
    tables
    binary_tab = bindata.
    Now when I upload any file text or image file, its working fine. When I try to upload any pdf , XL or word document, it uploads the file into acchived table
    but when I read this file by converting file data into xstring and passing it into file downlod UI element, It says file is corrupt. Please suggest that if that
    is a issue with object catagory configration ( With storage class) or it is wrong way of reading a document for PDF, XL and word
    Thanks in advance
    Abhay

    hi
    please check the function module used whether it can handle the PDF as well as xl, word documents. if not use some other function module

  • MIGO Unable to store information without posting items.

    MIGO The delivery note cannot be added and saved in the MIGO transaction without posting one of the items. I just want to store te delivery note and someone else is responsible for posting the items. How can I solve this problem?
    Regards, Jochen

    Hi,
    Thanks for replying to my question. The hold function in the MIGO transaction is not working as it do not held the data without posting the goods. The process at the customer is:
    One person who stands at the gate recieves the boxes (with goods) and fill in the delivery note. He only counts the number of boxes and does not check what is in the boxes. Then the goods are transported via a role bank to another person. Which is responsible for checking if the right goods are delivered. It can take a while before the GR is posted by this person therefore the organization wants to know if the goods are already received in the org.
    You talk about making the field mandatory, how can I do that? Thanks in advance for your answer!
    Kind regards,
    Jochen

  • Unable to store data into the Table(R/3)

    Dear All,
    our requirment is to store few records into the Table in R/3.
    We have update RFC which takes input arguments as AbstractList , the following is the code used to store data in the table(R/3)
    Zhr_Update input = new Zhr_Update();
    AbstractList list= new Zhr_Aprsl_Crs.Zhr_Aprsl_Crs_List();
    for(in i=0;i<wdContext.DvelpmntCodes().size();i++)
      crs= new Zhr_Aprsl_Crs();
      crs.setcid(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcode(i));
      crs.setDesp(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcodDesp(i));
       crs.setYear(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcodeYear(i));
    list.add(crs);;
    input.setcrs_chr_data(list);
    wdContext.Zhr_Update_Input().bind(input);
    wdContext.nodeZhr_Update_Input().currentZhr_Update_InputElement().modelObject().execute();
    The RFC is executing sucessfully without errors but data is not stored in the R/3 table
    Thanks,
    vijay.
    Edited by: vijay krishna on Oct 12, 2009 11:21 AM

    Hi,
    Use the following code to fix the issue
    for(in i=0;i<wdContext.DvelpmntCodes().size();i++)
    crs= new Zhr_Aprsl_Crs();
    crs.setcid(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcode(i));
    crs.setDesp(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcodDesp(i));
    crs.setYear(wdContext.DvelpmntCodes().getDvelpmntCodesElementAt(i).getcodeYear(i));
    input.addcrs_Obj_data(crs);
    wdContext.nodeZhr_Update_Input().moveNext();
    wdContext.Zhr_Update_Input().bind(input);

Maybe you are looking for

  • T410s with extremely poor performanc​e and CPU always near 100% usage

    Hi, I've had my T410s for almost a year now and lately its been starting to get extremely slow, which is odd since it used to be so fast. Just by opening one program, Outlook, or IE or Chrome, just one window, it will start to get extremely slow and

  • Request forward with a PDF file is not working in 8.1 SP2?

              Hi,           I have a servlet that forwards the request to a pdf file. The code works fine           in WL61. However when I ran the servlet in WL8.1SP2, all I get is a blank page.           However, instead of PDF I forward the request to

  • INTRASTAT/ EXTRASTAT- OUTPUT FIELDS

    Hello Experts, For intrastat and extrastat reporting , for italy, when i run MEIS for intrastat i get the following fields in the output. Our Italian client requires the intrastat to be sorted as per vendor VAT number and commercial code is this the

  • Share iCloud KeyChain & Bookmarks?

    Hey gang... I have a question as it relates to iCloud and more specifically, icloud Keychain. Up until now, the way my wife and I have things setup is we have one family icloud account which we use for all our iTunes and Apple Store purchases and the

  • Hierarchical query with multiple roots

    Hi, I'm trying to write a sql query to find blocking lock in database. The idea is to get the blocker in 1st column, comma separated list of waiters in 2nd column and number of waiters in 3rd column. As of now i use below query to get a tree structur