Code example for X509EncodedKeySpec

0
	private static String alg;
	private static String KEYGEN = "DSA";
 
	 
	public static void setKey(String keyString) throws InvalidKeySpecException, NoSuchAlgorithmException {
		key = KeyFactory.getInstance(KEYGEN).generatePublic(
				new X509EncodedKeySpec(Base64.decodeBase64(keyString)));
	} 
 
	public static void setSigAlg(String sigAlg) {
		alg = sigAlg;
	} 
 
	public static boolean verify(byte[] signature)
			throws NoSuchAlgorithmException, InvalidKeyException, 
			SignatureException { 
		Signature sig = Signature.getInstance(alg);
		sig.initVerify(key);
		return sig.verify(signature);
	}