- 24 May 2024
- 5
- 2
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class RAMFileEncryption {
public static void main(String[] args) {
try {
// Dosyadan okuma ve şifreleme
String originalContent = readFromFile("ram.txt");
String encryptedContent = encryptToBase64(originalContent);
// Şifrelenmiş içerik dosyaya yazma
writeToFile("encrypted_ram.txt", encryptedContent);
// Şifrelenmiş dosyadan okuma ve çözme
String decryptedContent = decryptFromBase64(readFromFile("encrypted_ram.txt"));
// Çözülmüş içeriği ekrana yazdırma
System.out.println("Decrypted Content:\n" + decryptedContent);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String readFromFile(String filePath) throws Exception {
StringBuilder content = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
content.append(line);
}
}
return content.toString();
}
private static void writeToFile(String filePath, String content) throws Exception {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath))) {
bw.write(content);
}
}
private static String encryptToBase64(String input) {
byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
byte[] encodedBytes = Base64.getEncoder().encode(bytes);
return new String(encodedBytes, StandardCharsets.UTF_8);
}
private static String decryptFromBase64(String input) {
byte[] decodedBytes = Base64.getDecoder().decode(input.getBytes(StandardCharsets.UTF_8));
return new String(decodedBytes, StandardCharsets.UTF_8);
}
}
Elimizde bir veri dosyasi var bunu alip decode edip sifrelenmis bir veriyi anlamli bir metine donusturecek yardimci olabilecek varmi kod calisiyor mantigini anlamak istiyorum
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class RAMFileEncryption {
public static void main(String[] args) {
try {
// Dosyadan okuma ve şifreleme
String originalContent = readFromFile("ram.txt");
String encryptedContent = encryptToBase64(originalContent);
// Şifrelenmiş içerik dosyaya yazma
writeToFile("encrypted_ram.txt", encryptedContent);
// Şifrelenmiş dosyadan okuma ve çözme
String decryptedContent = decryptFromBase64(readFromFile("encrypted_ram.txt"));
// Çözülmüş içeriği ekrana yazdırma
System.out.println("Decrypted Content:\n" + decryptedContent);
} catch (Exception e) {
e.printStackTrace();
}
}
private static String readFromFile(String filePath) throws Exception {
StringBuilder content = new StringBuilder();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
content.append(line);
}
}
return content.toString();
}
private static void writeToFile(String filePath, String content) throws Exception {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath))) {
bw.write(content);
}
}
private static String encryptToBase64(String input) {
byte[] bytes = input.getBytes(StandardCharsets.UTF_8);
byte[] encodedBytes = Base64.getEncoder().encode(bytes);
return new String(encodedBytes, StandardCharsets.UTF_8);
}
private static String decryptFromBase64(String input) {
byte[] decodedBytes = Base64.getDecoder().decode(input.getBytes(StandardCharsets.UTF_8));
return new String(decodedBytes, StandardCharsets.UTF_8);
}
}
Elimizde bir veri dosyasi var bunu alip decode edip sifrelenmis bir veriyi anlamli bir metine donusturecek yardimci olabilecek varmi kod calisiyor mantigini anlamak istiyorum