Next,
VerSig
needs to import the encoded public key bytes from the file specified as the first command line argument and to convert them to a PublicKey
. A PublicKey
is needed because that is what the Signature
initVerify
method requires in order to initialize the Signature
object for verification.
First, read in the encoded public key bytes.
Apr 23, 2012 Use the Java keytool to create public and private keys for RSA authentication if the client is in Java. Generating a RSA Key with the Java Keytool Use the Java keytool to create public and private keys for RSA authentication if the client is in Java. How to use.key and.crt file in java that generated by openssl? And public key correctly so that Java can read them? Private key to generate public key?
Now the byte array
encKey
contains the encoded public key bytes.
You can use a
KeyFactory
class in order to instantiate a DSA public key from its encoding. The KeyFactory
class provides conversions between opaque keys (of type Key
) and key specifications, which are transparent representations of the underlying key material. Elliptic curve cryptography key size. With an opaque key you can obtain the algorithm name, format name, and encoded key bytes, but not the key material, which, for example, may consist of the key itself and the algorithm parameters used to calculate the key. (Note that PublicKey
, because it extends Key
, is itself a Key
.)
So, first you need a key specification. You can obtain one via the following, assuming that the key was encoded according to the X.509 standard, which is the case, for example, if the key was generated with the built-in DSA key-pair generator supplied by the SUN provider:
Now you need a
KeyFactory
object to do the conversion. That object must be one that works with DSA keys.
Finally, you can use the
KeyFactory
object to generate a PublicKey
Generate ssh key github. from the key specification.
Public Key Definition
Java Read Public Key Generate Private Key From Bitcoin Address
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : algid parse error, not a sequence
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:175)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:342)
at cl.sii.dte.Autorizacion.setDOMElement(Autorizacion.java:282)
at cl.itplus.FacturaITPlus.caf.CargarAutorizacion.cargarAutorizacionfromFile(CargarAutorizacion.java:56)
at cl.itplus.FacturaITPlus.caf.CargarAutorizacion.main(CargarAutorizacion.java:89)
Caused by: java.security.InvalidKeyException: IOException : algid parse error, not a sequence
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:344)
at sun.security.pkcs.PKCS8Key.decode(PKCS8Key.java:350)
at sun.security.rsa.RSAPrivateCrtKeyImpl.<init>(RSAPrivateCrtKeyImpl.java:74)
at sun.security.rsa.RSAPrivateCrtKeyImpl.newKey(RSAPrivateCrtKeyImpl.java:58)
at sun.security.rsa.RSAKeyFactory.generatePrivate(RSAKeyFactory.java:274)
at sun.security.rsa.RSAKeyFactory.engineGeneratePrivate(RSAKeyFactory.java:171)
.. 4 more