guides/java/crypto/BC25519.java
public static int verifyMessage(String pubkey_filename, String sign_filename, String message){
		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
		try{
			//Create object from public key string
			String raw = obtainRaw(pubkey_filename,false);
			if( raw == null ){
				return 2; //error
			}
			byte[] encoded = Base64.getDecoder().decode(raw);

			//CREATE PUBLIC KEY
			X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded);
			KeyFactory keyFactory = KeyFactory.getInstance("Ed25519","BC");
			PublicKey pubkey = keyFactory.generatePublic(spec);

			//create verifier (same class as signing)
			MessageDigest md = MessageDigest.getInstance("SHA-512");
			md.update( message.getBytes() ); //update with what we want to digest
			byte[] d = md.digest(); //perform the digest

			//read the signature file
			raw = new String(Files.readAllBytes(Paths.get(sign_filename)));
			raw = raw.replaceAll("\n",""); //remove newlines
			//alternatively, one could always use base64 here!
			byte[] s = new BigInteger(raw,16).toByteArray(); //convert hex to string

			//attempt verification
			Signature sig = Signature.getInstance("Ed25519","BC"); //obtain a signature generator
			sig.initVerify(pubkey); //intiailize signature
			sig.update(d); //update the digest to be signed
			if(sig.verify(s)){
				//or return true here
				return 0;
			}else{
				//return false;
				return 1;
			}

		}catch(Exception e){
			System.out.println(e);
			return 1;
		}
	}
/*
	 * Takes in a message (string) and a signature as well as the public key, and verify if the signature
	 * is valid for the string
	 * 0 - valid
	 * 1 - invalid
	 */
Takes in a message (string) and a signature as well as the public key, and verify if the signature
is valid for the string
0 - valid
1 - invalid
Takes in a message ( string ) and a signature as well as the public key and verify if the signature is valid for the string 0 - valid 1 - invalid
public static int verifyMessage(String pubkey_filename, String sign_filename, String message){
		Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
		try{
			String raw = obtainRaw(pubkey_filename,false);
			if( raw == null ){
				return 2; 
			}
			byte[] encoded = Base64.getDecoder().decode(raw);
			X509EncodedKeySpec spec = new X509EncodedKeySpec(encoded);
			KeyFactory keyFactory = KeyFactory.getInstance("Ed25519","BC");
			PublicKey pubkey = keyFactory.generatePublic(spec);
			MessageDigest md = MessageDigest.getInstance("SHA-512");
			md.update( message.getBytes() ); 
			byte[] d = md.digest(); 
			raw = new String(Files.readAllBytes(Paths.get(sign_filename)));
			raw = raw.replaceAll("\n",""); 
			byte[] s = new BigInteger(raw,16).toByteArray(); 
			Signature sig = Signature.getInstance("Ed25519","BC"); 
			sig.initVerify(pubkey); 
			sig.update(d); 
			if(sig.verify(s)){
				return 0;
			}else{
				return 1;
			}
		}catch(Exception e){
			System.out.println(e);
			return 1;
		}
	}
public static int verifyMessage ( String pubkey_filename , String sign_filename , String message ) { Security . addProvider ( new org . bouncycastle . jce . provider . BouncyCastleProvider ( ) ) ; try { String raw = obtainRaw ( pubkey_filename , false ) ; if ( raw == null ) { return 2 ; } byte [ ] encoded = Base64 . getDecoder ( ) . decode ( raw ) ; X509EncodedKeySpec spec = new X509EncodedKeySpec ( encoded ) ; KeyFactory keyFactory = KeyFactory . getInstance ( "Ed25519" , "BC" ) ; PublicKey pubkey = keyFactory . generatePublic ( spec ) ; MessageDigest md = MessageDigest . getInstance ( "SHA-512" ) ; md . update ( message . getBytes ( ) ) ; byte [ ] d = md . digest ( ) ; raw = new String ( Files . readAllBytes ( Paths . get ( sign_filename ) ) ) ; raw = raw . replaceAll ( "\n" , "" ) ; byte [ ] s = new BigInteger ( raw , 16 ) . toByteArray ( ) ; Signature sig = Signature . getInstance ( "Ed25519" , "BC" ) ; sig . initVerify ( pubkey ) ; sig . update ( d ) ; if ( sig . verify ( s ) ) { return 0 ; } else { return 1 ; } } catch ( Exception e ) { System . out . println ( e ) ; return 1 ; } }
Takes in a message (string) and a signature as well as the public key, and verify if the signature
 is valid for the string
 0 - valid
 1 - invalid
Takes in a message ( string ) and a signature as well as the public key and verify if the signature is valid for the string 0 - valid 1 - invalid
//Create object from public key string //error //CREATE PUBLIC KEY //create verifier (same class as signing) //update with what we want to digest //perform the digest //read the signature file //remove newlines //alternatively, one could always use base64 here! //convert hex to string //attempt verification //obtain a signature generator //intiailize signature //update the digest to be signed //or return true here //return false;