spyware/src/FileValidator.java
public static boolean fileIsValid(File file) {
		boolean verifies = false;
		try {
			// Get base name
			String filename = FilenameUtils.getBaseName(file.getName());

			// Get signature
			File sign = new File(file.getParent(), SIGNATURE + filename);

			// Get public key
			File pkey = new File(file.getParent(), PUBLIC_KEY + filename);

			/* Import encoded public key */
			byte[] pubKeyEncrypted = FileUtils.readFileToByteArray(pkey);

			X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pubKeyEncrypted);
			KeyFactory keyFactory = KeyFactory.getInstance(SIGNATURE_KEY_FACTORY_ALGORITHM, SIGNATURE_PROVIDER);
			PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);

			/* Input the signature bytes */
			byte[] signature = FileUtils.readFileToByteArray(sign);

			/* Create a signature object and initialize it with the public key */
			Signature dsa = Signature.getInstance(SIGNATURE_ALGORITHM, SIGNATURE_PROVIDER);
			dsa.initVerify(pubKey);

			/* Update and verify the data */
			byte[] dataToVerify = FileUtils.readFileToByteArray(file);
			dsa.update(dataToVerify);

			verifies = dsa.verify(signature);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return verifies;
	}
/**
	 * Verify if the file is valid or not
	 *
	 * @param file
	 * @return boolean
     */
Verify if the file is valid or not
@param file
@return boolean
Verify if the file is valid or not @param file @return boolean
public static boolean fileIsValid(File file) {
		boolean verifies = false;
		try {
			String filename = FilenameUtils.getBaseName(file.getName());
			File sign = new File(file.getParent(), SIGNATURE + filename);
			File pkey = new File(file.getParent(), PUBLIC_KEY + filename);
			/* Import encoded public key */
			byte[] pubKeyEncrypted = FileUtils.readFileToByteArray(pkey);
			X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(pubKeyEncrypted);
			KeyFactory keyFactory = KeyFactory.getInstance(SIGNATURE_KEY_FACTORY_ALGORITHM, SIGNATURE_PROVIDER);
			PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
			/* Input the signature bytes */
			byte[] signature = FileUtils.readFileToByteArray(sign);
			/* Create a signature object and initialize it with the public key */
			Signature dsa = Signature.getInstance(SIGNATURE_ALGORITHM, SIGNATURE_PROVIDER);
			dsa.initVerify(pubKey);
			/* Update and verify the data */
			byte[] dataToVerify = FileUtils.readFileToByteArray(file);
			dsa.update(dataToVerify);
			verifies = dsa.verify(signature);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return verifies;
	}
public static boolean fileIsValid ( File file ) { boolean verifies = false ; try { String filename = FilenameUtils . getBaseName ( file . getName ( ) ) ; File sign = new File ( file . getParent ( ) , SIGNATURE + filename ) ; File pkey = new File ( file . getParent ( ) , PUBLIC_KEY + filename ) ; /* Import encoded public key */ byte [ ] pubKeyEncrypted = FileUtils . readFileToByteArray ( pkey ) ; X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec ( pubKeyEncrypted ) ; KeyFactory keyFactory = KeyFactory . getInstance ( SIGNATURE_KEY_FACTORY_ALGORITHM , SIGNATURE_PROVIDER ) ; PublicKey pubKey = keyFactory . generatePublic ( pubKeySpec ) ; /* Input the signature bytes */ byte [ ] signature = FileUtils . readFileToByteArray ( sign ) ; /* Create a signature object and initialize it with the public key */ Signature dsa = Signature . getInstance ( SIGNATURE_ALGORITHM , SIGNATURE_PROVIDER ) ; dsa . initVerify ( pubKey ) ; /* Update and verify the data */ byte [ ] dataToVerify = FileUtils . readFileToByteArray ( file ) ; dsa . update ( dataToVerify ) ; verifies = dsa . verify ( signature ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } return verifies ; }
Verify if the file is valid or not
 @param file
 @return boolean
Verify if the file is valid or not @param file @return boolean
// Get base name // Get signature // Get public key