Boa tarde, Camila!
Da uma olhada nessa função, se te ajuda.

function assinaturaBase64 ( i_url       in varchar2,
                             i_chave     in varchar2,
                             i_namespace in varchar2,
                             i_ds_ass    in varchar2,
                             io_errcode  in out number,
                             io_errtext  in out varchar2 ) return varchar2 is

   w_chave_src               varchar2(100) := i_chave;
   w_chave_b64               varchar2(100) := translate ( w_chave_src, '-_', 
'+/' );
   w_chave_bin               raw(2000);
   w_url                     varchar2(100) := utl_url.escape ( i_url );
   w_ass_mac                 raw(2000);
   w_base64_ass_mac          varchar2(2000);
   w_base64_ass_mac_alter    varchar2(2000);
   w_programa                varchar2(50);
   w_acao                    varchar2(50);

begin
   --
   w_chave_bin            := utl_encode.base64_decode ( utl_i18n.string_to_raw 
( w_chave_b64, 'AL32UTF8' ) );
   w_ass_mac              := dbms_crypto.mac ( utl_i18n.string_to_raw ( w_url, 
'AL32UTF8'),
                                               dbms_crypto.hmac_sh1, 
w_chave_bin );
   w_base64_ass_mac       := utl_raw.cast_to_varchar2 ( 
UTL_ENCODE.base64_encode ( w_ass_mac ) );
   w_base64_ass_mac_alter := translate ( w_base64_ass_mac, '+/', '-_' );
  --
   return i_namespace || i_url || i_ds_ass || w_base64_ass_mac_alter;
exception
   when others then
        io_errcode := sqlcode;
        io_errtext := 'Gerar_assinatura: '||sqlerrm;
        return '';
end;










De: 
sentto-1682896-121823-1494361138-carlos.silva3=jbsfoods.com...@returns.groups.yahoo.com
 
[mailto:sentto-1682896-121823-1494361138-carlos.silva3=jbsfoods.com...@returns.groups.yahoo.com]
 Em nome de camilal...@yahoo.com.br [oracle_br]
Enviada em: terça-feira, 9 de maio de 2017 17:19
Para: oracle_br@yahoogrupos.com.br
Assunto: [oracle_br] Re: Criptografia EAS 128 com Base64 no Oracle 11g



Boa tarde Chiappa,

vou tentar explicar melhor. É o seguinte, eu tenho um chave em Base64 que tenho 
que utilizar para criptografar e descriptografar informações.
Essas funções serão utilizadas na chamadas de serviços web para fazer a 
comunicação entre o meu sistema Oracle e um outro sistema Web.
O sistema web possui também rotinas para criptografar e descriptografar, e o 
meu sistema devera também possuir as mesmas funções. A chave utilizada pelos 
dois sistemas também sera a mesma.

No sistema web estão utilizando da seguinte forma:

public String cifrar(String textoOriginal, String chave) throws 
CriptografiaException {
        try {
            byte[] original = textoOriginal.getBytes("UTF-8");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, gerarChave(chave));
            byte[] cifrada = cipher.doFinal(original);
            byte[] retorno = Base64.encodeBase64(cifrada);
            return new String(retorno);
        } catch (UnsupportedEncodingException | NoSuchAlgorithmException | 
NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | 
BadPaddingException ex) {
            throw new CriptografiaException(ex);
        }
    }

    public String decifrar(String textoCifrado, String chave) throws 
CriptografiaException {
        try {
            byte[] cifrado = Base64.decodeBase64(textoCifrado.getBytes());
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(Cipher.DECRYPT_MODE, gerarChave(chave));
            byte[] decifrado = cipher.doFinal(cifrado);
            return new String(decifrado, "UTF-8");
        } catch (UnsupportedEncodingException | NoSuchAlgorithmException | 
NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | 
BadPaddingException ex) {
            throw new CriptografiaException(ex);
        }
    }

Eu preciso criar as mesmas funções no Oracle 11g. No exemplo abaixo, eu tentei 
utilizar assim:

Os valores de G_STRING e P_VAL estavam em Base64 que eu transformei em  RAW:
G_STRING :=utl_raw.cast_to_raw('chave em base64');
-- RAW PARA BASE64
G_STRING := utl_encode.base64_encode(G_STRING);

P_VAL :=utl_raw.cast_to_raw('Informação criptografada em EAS convertida em 
Base64');
-- RAW PARA BASE64
P_VAL := utl_encode.base64_encode(P_VAL);

Para criar minha função para descriptografar a informação que recebi do sistema 
web, eu fiz da seguinte forma:

 DECLARE
    G_CHARACTER_SET VARCHAR2(10) := 'AL32UTF8';
    G_STRING RAW(32767) := 'EF5674A75A3EE327EC319B9F5C5BBE8B';
    G_KEY RAW(250) := utl_i18n.string_to_raw
                      ( data => G_STRING,
                      dst_charset => G_CHARACTER_SET );
    G_ENCRYPTION_TYPE PLS_INTEGER := dbms_crypto.encrypt_aes256
                                     + dbms_crypto.chain_cbc
                                     + dbms_crypto.pad_pkcs5;

    l_decrypted RAW(32);
    l_decrypted_string VARCHAR2(32);

    p_val RAW(32767) := 
'430287A8AA1F9AE894A3BCE45A2CDD239CA12E68E584598D5486B85A2BFB1F31';
 BEGIN
        l_decrypted := dbms_crypto.decrypt
                ( src => p_val,
                  typ => G_ENCRYPTION_TYPE,
                  key => G_KEY );

        l_decrypted_string := utl_i18n.raw_to_char
                    ( data => l_decrypted,
                      src_charset => G_CHARACTER_SET );
     dbms_output.put_line(l_decrypted_string);
END;

Esse exemplo me retorna um erro:
elatório de erro:
ORA-28817: A função PL/SQL retornou um erro.
ORA-06512: em "SYS.DBMS_CRYPTO_FFI", line 67
ORA-06512: em "SYS.DBMS_CRYPTO", line 44
ORA-06512: em line 16
28817. 00000 -  "PL/SQL function returned an error."
*Cause:    A PL/SQL function returned an error unexpectedly.
*Action:   This is an internal error. Contact Oracle customer support.

Não sei se consegui ser mais clara desa vez, mas obrigada!!







  • ... camilal...@yahoo.com.br [oracle_br]
    • ... jlchia...@yahoo.com.br [oracle_br]
      • ... jlchia...@yahoo.com.br [oracle_br]
        • ... camilal...@yahoo.com.br [oracle_br]
          • ... Carlos Cesar Aparecido Da Silva carlos.sil...@jbsfoods.com.br [oracle_br]
            • ... camilal...@yahoo.com.br [oracle_br]

Responder a