![Java.security.spec.invalidkeyspecexception Java.security.spec.invalidkeyspecexception](/uploads/1/2/7/0/127057005/623949156.png)
I'll assume that you want to generate a wrapped PKCS#8 private key. PKCS#8 however has both an inner and external DER encoded structure around it. The inner structure is to identify the stored key, i.e. It will indicate an RSA private key. This is what's being wrapped. The outer structure will indicate how the private key was wrapped.
- Exception in thread 'main' java.security.spec.InvalidKeySpecException: Could not generate secret key at javax.crypto.SecretKeyFactory.generateSecret(Unknown Source).
- Jan 14, 2016 I wanted to encrypt a config value using the RSA algorithm. I also wanted to 'publish' the public key, and keep the private key private. Generating RSA key: # java -jar hello-dw.jar generate-random-key -a RSA Wrote key to var/conf/encryp.
- Not a member of Pastebin yet? Sign Up, it unlocks many cool features! Raw download clone embed report print text 4.97 KB java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Detect premature EOF. Byte key = Base64.encodeBase64(publicKey.getBytes).
Elasticsearch Java.security.spec.invalidkeyspecexception Could Not Generate Secret Key
- java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: Detect premature EOF
- at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:188)
- at java.security.KeyFactory.generatePublic(KeyFactory.java:304)
- at com.josh.crypto.CryptoUtil.convertKeytoKeyObject(CryptoUtil.java:96)
- at com.josh.crypto.CryptoUtil.encryptData(CryptoUtil.java:78)
- at com.josh.ui.EncryptionView$2.actionPerformed(EncryptionView.java:112)
- at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
- at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
- at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
- at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
- at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
- at java.awt.Component.processMouseEvent(Component.java:6382)
- at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
- at java.awt.Component.processEvent(Component.java:6147)
- at java.awt.Container.processEvent(Container.java:2083)
- at java.awt.Component.dispatchEventImpl(Component.java:4744)
- at java.awt.Container.dispatchEventImpl(Container.java:2141)
- at java.awt.Component.dispatchEvent(Component.java:4572)
- at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
- at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
- at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
- at java.awt.Container.dispatchEventImpl(Container.java:2127)
- at java.awt.Window.dispatchEventImpl(Window.java:2489)
- at java.awt.Component.dispatchEvent(Component.java:4572)
- at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
- at java.awt.EventQueue.access$400(EventQueue.java:82)
- at java.awt.EventQueue$2.run(EventQueue.java:663)
- at java.awt.EventQueue$2.run(EventQueue.java:661)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
- at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
- at java.awt.EventQueue$3.run(EventQueue.java:677)
- at java.awt.EventQueue$3.run(EventQueue.java:675)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
- at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
- at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
- at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
- at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
- at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
- at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
- at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
- Caused by: java.security.InvalidKeyException: IOException: Detect premature EOF
- at sun.security.x509.X509Key.decode(X509Key.java:380)
- at sun.security.x509.X509Key.decode(X509Key.java:386)
- at sun.security.rsa.RSAPublicKeyImpl.<init>(RSAPublicKeyImpl.java:66)
- at sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:281)
- at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:184)
- private PublicKey convertKeytoKeyObject(String publicKey)
- throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
- byte[] key = Base64.encodeBase64(publicKey.getBytes());
- keyFactory = KeyFactory.getInstance(Keys.RSA);
- Comment: 'rsa-key-20130520'
- AAAAB3NzaC1yc2EAAAABJQAAAIEAsE8aR2CIWuQgkeOsPhHDuGo+Rokr2cT+KS5L
- sJFbEkB0R3XYXnOT3DU0CFrmHUX1PpcfTOSdxCIfeSXFHCGGWEXm4qx7ptNpm4vP
- Scuzmlr/fjuQdb7lBQ0+OEP2LKuRHxt5oEVZvq/EvwENS5T2BiVUSvTwXUS6SKCh
- ---- END SSH2 PUBLIC KEY ----
- 1023 37 76983149213904336854114697871156413897597333013960300274862161645944637611303244321149406756964434094764396730933825927553585120754675001147670015123442685209165940390638704889262818745065195784329243512386761389890962501775294435871155079992876425567019740053306097979712960040526841676998224241040015724649 rsa-key-20130520
- SecureRandom rand = new SecureRandom();
- try {
- }
- System.err.println( e.getMessage());
- gen.initialize ( 1024, rand );
- PublicKey pubkey = keys.getPublic ();
- System.out.println ( pubkey.toString ());
- writeKeyToFile ( privkey, FILE_PRIVATE_KEY );
Constructor Detail
InvalidKeyException
Constructs an InvalidKeyException with no detail message. A detail message is a String that describes this particular exception.
InvalidKeyException
Constructs an InvalidKeyException with the specified detail message. A detail message is a String that describes this particular exception.- Parameters:
msg
- the detail message.
InvalidKeyException
Creates aInvalidKeyException
with the specified detail message and cause.- Parameters:
message
- the detail message (which is saved for later retrieval by theThrowable.getMessage()
method).cause
- the cause (which is saved for later retrieval by theThrowable.getCause()
method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)- Since:
- 1.5
InvalidKeyException
Creates aInvalidKeyException
with the specified cause and a detail message of (causenull ? null : cause.toString()) (which typically contains the class and detail message of cause).- Parameters:
cause
- the cause (which is saved for later retrieval by theThrowable.getCause()
method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)- Since:
- 1.5