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 ::  
::  
::  
::  
:: data to string format java 
Java :: How to find the Levenshtein distance between two strings of characters, in Java? 
Java ::  
Java :: org.springframework.orm.jpa.EntityManagerHolder cannot be cast to org.springframework.orm.hibernate5.SessionHolder 
::  
Java ::  
:: check if string has a valid number java 
::  
::  
Java ::  
Java :: primefaces custom validate 
::  
::  
:: how to set the backtound color in java 
Java :: Java code to print odd number 
Java ::  
::  
::  
Java :: bukkit scheduled task 
Java ::  
Java ::  
:: test if string is float java 
Java :: .now() java 
Java ::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
8+4 =