I want to get an image from a url, convert it into bytes and encrypt it using AES. However, when I try to compile the code for my Server, I get this error:
Why is this so? Below is the code for my server which generates an AES key and tries to convert a image url to bytes.Server1.java:77: error: cannot find symbol plainpic = Base64.getUrlEncoder().encodeToString(myimage.getBytes()); symbol: method getBytes() location: variable myimage of type URL
Server1.java
public class Server1 { public static void main (String [] args ) throws InvalidKeyException, IOException, Exception { ServerSocket serverSocket = new ServerSocket(15123); Socket socket = null; //start of AES //Generate AES Key int sizeofkey = 128; KeyGenerator kg = KeyGenerator.getInstance("AES"); //initialize with sizeofkey kg.init(sizeofkey); Key mykey = kg.generateKey(); System.out.println("Key Generated"); //create cipher object & initialize with generated key Cipher cipher = Cipher.getInstance("AES/ECB/PCKS5PADDING"); cipher.init(Cipher.ENCRYPT_MODE, mykey); while(true) { socket = serverSocket.accept(); System.out.println("Accepted connection : " + socket.getRemoteSocketAddress().toString() + " <-> /127.0.0.1:15123" ); DataOutputStream dos = new DataOutputStream(socket.getOutputStream()); // get the image from a webcam URL myimage = new URL("http://183.76.13.58:80/SnapshotJPEG?Resolution=640x480"); DataInputStream in = null; String plainpic = null; try { in = new DataInputStream(myimage.openStream()); //Error plainpic = Base64.getUrlEncoder().encodeToString(myimage.getBytes()); } catch (Exception ee) { System.out.println("Check internet connection please"); socket.close(); return; } DateFormat dateFormat = new SimpleDateFormat("yy/MM/dd HH:mm:ss"); Date date = new Date(); System.out.println("Sending image " + dateFormat.format(date)); try { while (true) { dos.writeByte(in.readByte()); } } catch (EOFException ee) { System.out.println("-------------- Done ----------"); in.close(); } dos.flush(); dos.close(); socket.close(); } } }