com.github.jhonyscamacho.finaluser.encryption.EncryptionSHA3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of final-user Show documentation
Show all versions of final-user Show documentation
A bunch of classes that help developers building login and authentication.
The newest version!
package com.github.jhonyscamacho.finaluser.encryption;
import java.security.MessageDigest;
import org.bouncycastle.jcajce.provider.digest.SHA3.DigestSHA3;
import org.bouncycastle.jcajce.provider.digest.SHA3.Digest256;
/**
* Esse tipo de Criptografia só encriptografa, mas não descriptografa.
*
**/
public class EncryptionSHA3 implements Encryption {
private static Encryption instance;
private EncryptionSHA3() { }
public static Encryption getInstance(){
if(instance == null)
instance = new EncryptionSHA3();
return instance;
}
@Override
public String encrypt(String data) {
DigestSHA3 sha3 = new Digest256();
sha3.update(data.getBytes());
return messageDigestHashToString(sha3);
}
private String messageDigestHashToString(MessageDigest hash) {
return byteToString(hash.digest());
}
private String byteToString(byte[] hash) {
StringBuffer buff = new StringBuffer();
for (byte b : hash) {
buff.append(String.format("%02x", b & 0xFF));
}
return buff.toString();
}
public static void main(String[] args) {
EncryptionSHA3 teste = new EncryptionSHA3();
System.out.println(teste.encrypt("").length());
System.out.println(teste.encrypt(""));
System.out.println("\n");
System.out.println(teste.encrypt("12345678").length());
System.out.println(teste.encrypt("12345678"));
System.out.println("\n");
System.out.println(teste.encrypt("aucenirejhonathan").length());
System.out.println(teste.encrypt("aucenirejhonathan"));
System.out.println("\n");
System.out.println(teste.encrypt("lorin+gotinha=Casanova").length());
System.out.println(teste.encrypt("lorin+gotinha=Casanova"));
System.out.println("\n");
System.out.println(teste.encrypt("ççççççççççççççççççççççççççç aaaaaaaaaaaaaaaaaaaaaaaaaaaaa iiiiiiiiiiiiiiiiiiiiiiiiii eeeeeeeeeeeeeeeeeeeeeeeeeeeee").length());
System.out.println(teste.encrypt("ççççççççççççççççççççççççççç aaaaaaaaaaaaaaaaaaaaaaaaaaaaa iiiiiiiiiiiiiiiiiiiiiiiiii eeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy