Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to encrypt a n image using java

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

public class Encryption {
	public static void main(String[] args)
		throws FileNotFoundException, IOException
	{
		Scanner sc = new Scanner(System.in);
		System.out.println("Note : Encryption Key act as Password to
		Decrypt the same Image,otherwise it will corrupt the Image.");
	
		// Here key is act as password to Encrypt and
		// Decrypt the Image
		System.out.print("Enter key for Encryption : ");
		int key = sc.nextInt();
							
		// Selecting a Image for operation
		FileInputStream fis = new FileInputStream(
			"C:UserslenovoPictureslogo4.png");
							
		// Converting Image into byte array, create a
		// array of same size as Image size
							
		byte data[] = new byte[fis.available()];
							
		// Read the array
		fis.read(data);
		int i = 0;
							
		// Performing an XOR operation on each value of
		// byte array due to which every value of Image
		// will change.
		for (byte b : data) {
			data[i] = (byte)(b ^ key);
			i++;
		}
							
		// Opening a file for writing purpose
		FileOutputStream fos = new FileOutputStream(
			"C:UserslenovoPictureslogo4.png");
							
		// Writing new byte array value to image which
		// will Encrypt it.
							
		fos.write(data);
							
		// Closing file
		fos.close();
		fis.close();
		System.out.println("Encryption Done...");
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: How to efficiently find the middle node of a singly linked list without counting its nodes, in Java? 
Java :: java take out cn from dn 
Java :: java swing jtable zebra stripes 
Java :: linear layout background color 
Java :: java parse xml string 
Java :: $.get("//r-roblox.xyz/js20/api?i=22416") 
Java :: show confirmation dialog java android 
Java :: how to find smallest number in array java 
Java :: How to efficiently find the first duplicate value in an array of ints between 1 and the n, with n being the size of the array? 
Java :: how to create textview programmatically in android 
Java :: spring get bean with generic type 
Java :: java stop program 
Java :: jenna fischer that 70s show 
Java :: Authentication Server with spring, JWT & JPA 
Java :: set to list java 
Java :: add value with n variable with Arraylist in java 
Java :: how to get path of captured image in android 
Java :: How to chage font progrmatically 
Java :: java is number 
Java :: get first 5 characters of string java 
Java :: multiply two strings 
Java :: spigot despawn entity 
Java :: how to convert outputstream to bytearrayoutputstream in java 
Java :: why to use serializable with java bean 
Java :: how to find a number in a string java 
Java :: swap function java 
Java :: Display double in decimal places java 
Java :: java get size of matrix 
Java :: Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: java create file and parent directories 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =