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

238
Visualizações
Convert function to javascript, calling from c++ to node.js server - encryption

I'm trying to encrypt a string using the juce framework generatekeypair, this create a RSA keypair and splits it into 2 parts, (and puts it in hex format I think).

This is the working code I'm using in c++:

const juce::String encryptString (const juce::String& str)
{
    juce::RSAKey private_key2 ("thisistheprivatekeypart1,thisistheprivatekeypart2");
    auto utf8 = str.toUTF8();
       auto* utf8Address = utf8.getAddress();
       juce::MemoryBlock plainMemoryBlock(utf8Address, utf8.sizeInBytes());

       juce::BigInteger sourceInteger;
       sourceInteger.loadFromMemoryBlock(plainMemoryBlock);

       if (!sourceInteger.isZero())
       {
           juce::BigInteger encodedInteger(sourceInteger);
           private_key2.applyToValue(encodedInteger);

           juce::MemoryBlock encodedMemoryBlock = encodedInteger.toMemoryBlock();

           return encodedMemoryBlock.toBase64Encoding();
       }

       return {};
}

Now i'm doing my first steps in node.js, i've successfully setup a server that takes and sends parameters, does anyone know how to write this function in node.js?

On the juce website they have this unconfirmed java snippet but it's not helping me a lot:

public class RSAKey
{
    static BigInteger applyToValue (BigInteger value, String key_part1, String key_part2)
    {
        BigInteger result = BigInteger.ZERO;
        BigInteger part1 = new BigInteger (key_part1, 16);
        BigInteger part2 = new BigInteger (key_part2, 16);
 
        if (part1.equals (BigInteger.ZERO) || part2.equals (BigInteger.ZERO)
             || value.compareTo (BigInteger.ZERO) <= 0)
            return result;
 
        while (! value.equals (BigInteger.ZERO))
        {
            result = result.multiply (part2);
            BigInteger[] div = value.divideAndRemainder (part2);
            value = div[0];
            result = result.add (div[1].modPow (part1, part2));
        }
 
        return result;
    }
}
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