Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
How to encrypt/decrypt in Javascript with DES?

I see encoding function on Java back-end and I need to write same functionality on NestJS (NodeJS). The result of these transformations is something like so C6EB48123226CDBB3A5048FE6A92CA06, I see it in a database table.

So, I tried to use cripto-js library, it works with DES encryption but I couldn't get result that looks like C6EB48123226CDBB3A5048FE6A92CA06.

As instance (works fine):

var encrypted = CryptoJS.DES.encrypt("DataFromInput", "secretKey");​
var decrypted = CryptoJS.DES.decrypt(encrypted, "secretKey"); 

But my question still is open. I don't have any idea that I have to do for getting string similar to C6EB48123226CDBB3A5048FE6A92CA06, because I don't understand that Java code below does and how I can implement it in Javascript.

I need some step-by-step instruction like: Encrypt string -> Take property X from result -> Transform it to array -> Get hash of array etc.

public static String getEncrypted( String str, String key )
{
    try
    {
        KeySpec keySpec = new DESKeySpec( key.getBytes( Charset.forName( "UTF-8")));
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( "DES");
        SecretKey desKey = keyFactory.generateSecret( keySpec);

        try ( ByteArrayOutputStream cipheredBaos = new ByteArrayOutputStream() )
        {
            Cipher desCipher = Cipher.getInstance( "DES/ECB/PKCS5Padding");
            desCipher.init( Cipher.ENCRYPT_MODE, desKey);

            CipherOutputStream cos = new CipherOutputStream( cipheredBaos, desCipher);
            cos.write( str.getBytes( "UTF-8"));
            cos.close( );
            
            return DatatypeConverter.printHexBinary( cipheredBaos.toByteArray( ));
        }
    }
    catch ( Exception e)
    {
        System.out.println( e.getMessage() );
        return "";
    }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda