Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Key generation and 64 \ 32 bit CPU's

803417Jan 9 2011 — edited Jan 9 2011
Hi,
signature verification isn't working

I'm generating signature keys and writing\reading them to\from files in the following ways (methods below).
Can there be an issue when working on 32 bit or 64 bit laptops\computers??
Everything is working fine on two 64 bit or on my 32 bit one,
but not working between 64 and 32 (*signature verification isn't working*).
I'm not attaching the sign and verify methods because there's nothing special there.
Thanks!!!!


	public static KeyPair generate() {
			KeyPair keyPair = null;
			try {

				KeyPairGenerator generate = KeyPairGenerator.getInstance("ECDSA", "FlexiEC");
				CurveParams ecParams = new Prime192v1();
				generate.initialize(ecParams, new SecureRandom());
				keyPair = generate.generateKeyPair();
				
			} catch (NoSuchAlgorithmException e) {
			} catch (NoSuchProviderException e) {
			} catch (InvalidAlgorithmParameterException e) {
			}
			return keyPair;
	}
	
	public static PrivateKey returnPrivKey(KeyPair keyPair){
		PrivateKey privateKey = null;
		try {
			privateKey = keyPair.getPrivate();
		} catch (Exception e) {
		}
		
		return privateKey; 
	}
	
	public static PublicKey returnPubKey(KeyPair keyPair){
		PublicKey publicKey = null;
		try {
			publicKey = keyPair.getPublic();
		} catch (Exception e) {
		}
		
		return publicKey; 
	}
	
	public static void writePubKeyToFile(KeyPair keyPair, String filename) throws IOException {
		
		try {
			PublicKey publicKey = keyPair.getPublic();
			File publicKeyFile = new File(filename);
			FileOutputStream pubFos = new FileOutputStream(publicKeyFile);
			pubFos.write(publicKey.getEncoded());
			pubFos.close();
		} catch (Exception e) {
		}
	}
	
	public static void writePrivKeyToFile(KeyPair keyPair, String filename) throws IOException {
		
		try {
			PrivateKey privateKey = keyPair.getPrivate();
			File privateKeyFile = new File(filename);
			FileOutputStream pubFos = new FileOutputStream(privateKeyFile);
			pubFos.write(privateKey.getEncoded());
			pubFos.close();
		} catch (Exception e) {
		}
	}
        
    public static PublicKey readPubKeyFromFile(String filename) throws java.security.spec.InvalidKeySpecException, 
    												NoSuchProviderException, IOException, NoSuchAlgorithmException {
    	

    	        ByteArrayOutputStream pubBos = new ByteArrayOutputStream();

		FileInputStream pubFis = new FileInputStream(new File(filename));
		
		int currentByte = 0;
		while ((currentByte = pubFis.read()) != -1){
			pubBos.write(currentByte);
		}
		
		X509EncodedKeySpec specPublicKey = new X509EncodedKeySpec(pubBos.toByteArray());
		pubBos.close();
		KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "FlexiEC");
		PublicKey publicKey = keyFactory.generatePublic(specPublicKey);
		return publicKey;
	}

  
	public static PrivateKey readPrivKeyFromFile(String filename) throws java.security.spec.InvalidKeySpecException, 
														NoSuchProviderException, IOException, NoSuchAlgorithmException {
		

		ByteArrayOutputStream privBos = new ByteArrayOutputStream();
		FileInputStream privFis = new FileInputStream(new File(filename));
		int currentByte = 0;
		while ((currentByte = privFis.read()) != -1){
			privBos.write(currentByte);
		}
		PKCS8EncodedKeySpec specPrivateKey = new PKCS8EncodedKeySpec(privBos.toByteArray());
		privBos.close();
		KeyFactory keyFactory = KeyFactory.getInstance("ECDSA", "FlexiEC");
		PrivateKey privateKey = keyFactory.generatePrivate(specPrivateKey);
		return privateKey;
	}
}
Edited by: 800414 on 05:29 09/01/2011

Edited by: 800414 on 07:40 09/01/2011
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2011
Added on Jan 9 2011
3 comments
207 views