Created
March 3, 2017 08:38
-
-
Save eliaperantoni/7c28a9ce656e0e4518e1f27a7858b3d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.yubico.client.v2.VerificationResponse; | |
import com.yubico.client.v2.YubicoClient; | |
import com.yubico.client.v2.exceptions.YubicoValidationFailure; | |
import com.yubico.client.v2.exceptions.YubicoVerificationException; | |
import javax.swing.*; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.InputStreamReader; | |
import java.net.Socket; | |
import java.util.Scanner; | |
class Main{ | |
static final String $4 = "ccccccgdjrll"; | |
static final String $4nano = "ccccccgenvei"; | |
public static void main(String[] args){ | |
//dialogWithServer(); | |
//cryptoFiles(); | |
//yubicoTest(); | |
} | |
static void dialogWithServer(){ | |
try { | |
String serverAddress = JOptionPane.showInputDialog( | |
"Indirizzo IP della macchina che\n" + | |
"risponde sulla porta 9090:"); | |
Socket s = new Socket(serverAddress, 9090); | |
BufferedReader input = | |
new BufferedReader(new InputStreamReader(s.getInputStream())); | |
String answer = input.readLine(); | |
JOptionPane.showMessageDialog(null, answer); | |
System.exit(0); | |
} | |
catch(Exception x) { | |
x.printStackTrace(); | |
} | |
} | |
static void yubicoTest(){ | |
YubicoClient client = YubicoClient.getClient(32131,"vxQ++dnryWncTfyJzTkrhDnDBuc="); | |
VerificationResponse response = null; | |
String x = JOptionPane.showInputDialog("OTP"); | |
try { | |
response = client.verify(x); | |
} catch (YubicoVerificationException e) { | |
e.printStackTrace(); | |
} catch (YubicoValidationFailure yubicoValidationFailure) { | |
yubicoValidationFailure.printStackTrace(); | |
} | |
String answer = ""; | |
switch(YubicoClient.getPublicId(x)){ | |
case $4: | |
answer += "E' la Yubikey standard"; | |
break; | |
case $4nano: | |
answer += "E' la Yubikey 4 nano"; | |
break; | |
} | |
answer += " \nPublic ID: "+YubicoClient.getPublicId(x); | |
answer += " \nValida : "+response.isOk(); | |
JOptionPane.showMessageDialog(null, answer); | |
} | |
static void cryptoFiles(){ | |
Scanner scan = new Scanner(System.in); | |
CryptoUtils crypto = new CryptoUtils("AES","AES"); | |
System.out.println("Che tipo di operazione vuoi eseguire?\n[1] Encrypt\n[2] Decrypt"); | |
String mode = scan.nextLine(); | |
System.out.println("Qual è il nome del file?"); | |
String fileName = scan.nextLine(); | |
switch (mode){ | |
case "1": | |
try { | |
File inputFile = new File("C:\\Users\\extensys\\Desktop\\"+fileName); | |
File outputFile = new File("C:\\Users\\extensys\\Desktop\\enc\\"+fileName+".encrypted"); | |
System.out.println(CryptoUtils.encrypt(inputFile,outputFile)); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
break; | |
case "2": | |
File inputFile = new File("C:\\Users\\extensys\\Desktop\\enc\\"+fileName+".encrypted"); | |
File outputFile = new File("C:\\Users\\extensys\\Desktop\\"+fileName); | |
System.out.println("Quale è la chiave?"); | |
String key = scan.nextLine(); | |
try { | |
CryptoUtils.decrypt(inputFile,outputFile,key); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment