Ya no busques más en otras webs porque estás al lugar justo, contamos con la solución que necesitas recibir pero sin complicarte.
Ejemplo: cifrado java aes
importjava.io.UnsupportedEncodingException;importjava.security.MessageDigest;importjava.security.NoSuchAlgorithmException;importjava.util.Arrays;importjava.util.Base64;importjavax.crypto.Cipher;importjavax.crypto.spec.SecretKeySpec;publicclass AES privatestaticSecretKeySpec secretKey;privatestaticbyte[] key;publicstaticvoidsetKey(String myKey)MessageDigest sha =null;try
key = myKey.getBytes("UTF-8");
sha =MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
key =Arrays.copyOf(key,16);
secretKey =newSecretKeySpec(key,"AES");catch(NoSuchAlgorithmException e)
e.printStackTrace();catch(UnsupportedEncodingException e)
e.printStackTrace();publicstaticStringencrypt(String strToEncrypt,String secret)trysetKey(secret);Cipher cipher =Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secretKey);returnBase64.getEncoder().encodeToString(cipher.doFinal(strToEncrypt.getBytes("UTF-8")));catch(Exception e)System.out.println("Error while encrypting: "+ e.toString());returnnull;publicstaticStringdecrypt(String strToDecrypt,String secret)trysetKey(secret);Cipher cipher =Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);returnnewString(cipher.doFinal(Base64.getDecoder().decode(strToDecrypt)));catch(Exception e)System.out.println("Error while decrypting: "+ e.toString());returnnull;
Recuerda que te permitimos agregar una reseña si diste con el arreglo.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)