Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda