Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
public class RsaTest {
public static void main(String[] args) throws Exception {
KeyPair k=KeyPairGenerator.getInstance("RSA").generateKeyPair(); //generiert die Schlüssel die zur Ver- und Entschlüsselung notwendig sind
// verschlüsseln
FileInputStream fis=new FileInputStream("/home/schirra/movies_451.jpg");
FileOutputStream fos=new FileOutputStream("/home/schirra/Desktop/test.rsa");
byte[] encrypt=new byte[1];
while(fis.read(encrypt)!=-1)
{
fos.write(CryptoRSA.encrypt(encrypt,k));
}
System.out.println("Verschlüsselt");
// entschlüsseln
FileInputStream in=new FileInputStream("/home/schirra/Desktop/test.rsa");
FileOutputStream out=new FileOutputStream("/home/schirra/Desktop/test2.jpg");
byte[] decrypt=new byte[128];
while(in.read(decrypt)!=-1)
{
out.write(CryptoRSA.decrypt(decrypt,k));
}
System.out.println("Entschlüsselt");
}
}
import java.security.KeyPair;
import javax.crypto.Cipher;
public class CryptoRSA {
public static byte[] encrypt(byte[] d, KeyPair keyPair) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
byte[] encrypt = cipher.doFinal(d);
return encrypt;
}
public static byte[] decrypt(byte[] d, KeyPair keyPair) throws Exception {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate());
byte[] decrypt = cipher.doFinal(d);
return decrypt;
}
}
package de.tutorials;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
public class SimpleFileChiffreExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
File file = new File("c:/Sonnenuntergang.jpg");
Cipher cipher = Cipher.getInstance("RSA");
KeyPair keyPair = KeyPairGenerator.getInstance("RSA").generateKeyPair();
cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());
BufferedInputStream bufferedInputStream = new BufferedInputStream(
new FileInputStream(file));
File encryptedFile = new File("c:/Sonnenuntergang_enc.jpg");
CipherOutputStream cipherOutputStream = new CipherOutputStream(
new FileOutputStream(encryptedFile), cipher);
byte[] buffer = new byte[8192];
int len = 0;
while ((len = bufferedInputStream.read(buffer)) >= 0) {
cipherOutputStream.write(buffer, 0, len);
}
cipherOutputStream.close();
bufferedInputStream.close();
cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate());
CipherInputStream cipherInputStream = new CipherInputStream(
new FileInputStream(encryptedFile), cipher);
File decryptedFile = new File("c:/Sonnenuntergang_dec.jpg");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
new FileOutputStream(decryptedFile));
while ((len = cipherInputStream.read(buffer)) >= 0) {
bufferedOutputStream.write(buffer, 0, len);
}
cipherInputStream.close();
bufferedOutputStream.close();
}
}