[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] JCE Applet Edition reporting iaik.java.security.SignatureException: Not in signing state.



Attempt 2:
 
I am trying to encrypt a String with an existing DSA private key, but the following code:
 
public static void main(String args[])
{
 try
 {
  iaik.java.security.Security.insertProviderAt(new iaik.security.provider.IAIK(), 1);
  iaik.security.provider.IAIK.addAsProvider(true);
  String password = "This is a test password numbered 0123456789";
  iaik.security.dsa.DSAPrivateKey iiclPrivateDsaKey = new iaik.security.dsa.DSAPrivateKey(new java.io.FileInputStream(new java.io.File("O:\\Technical\\javakey\\iicl_priv")));
  iaik.security.dsa.DSAPublicKey iiclPublicDsaKey = new iaik.security.dsa.DSAPublicKey(new java.io.FileInputStream(new java.io.File("O:\\Technical\\javakey\\iicl_pub")));
  iaik.java.security.Signature dsaSignature = iaik.security.dsa.DSA.getInstance("DSA");
  dsaSignature.initSign(iiclPrivateDsaKey);
  dsaSignature.initVerify(iiclPublicDsaKey);
  dsaSignature.update(password.getBytes());
  byte[] signedPasswordBytes = dsaSignature.sign();
  dsaSignature.update(password.getBytes());
  if (!(dsaSignature.verify(signedPasswordBytes)))
  {
   System.out.println("StringEncrypt.main(): failed to verify");
   System.exit(0);
  }
  String encryptedPassword = new String(signedPasswordBytes);
  System.out.println(encryptedPassword);
 }
 catch (Exception e)
 {
  System.out.println("StringEncrypt.main(): failed with " + e.getMessage());
  e.printStackTrace();
  System.exit(0);
 }
}
 
gives the following error:
 
StringEncrypt.main(): failed with Not in signing state.
iaik.java.security.SignatureException: Not in signing state.
 java.lang.Throwable(java.lang.String)
 java.lang.Exception(java.lang.String)
 iaik.java.security.SignatureException(java.lang.String)
 byte [] iaik.java.security.Signature.sign()
 void uk.co.streeter.dave.cryptography.test.StringEncryptWithSignature.main(java.lang.String [])
 
Please help.....
 

Regards

Dave Streeter