IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SQL Oracle Discussion :

Cryptage de colonnes sous Oracle [FAQ]


Sujet :

SQL Oracle

  1. #1
    Candidat au Club
    Inscrit en
    Octobre 2002
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 2
    Points : 2
    Points
    2
    Par défaut Cryptage de colonnes sous Oracle
    Salut,

    J'aimerai savoir s'il existe une fonction permettant de crypter / décrypter les données d'un attribut sous Oracle (pour crypter un mot de passe par exemple).

    Merci par avance

  2. #2
    Nouveau membre du Club

    Profil pro
    Inscrit en
    Mars 2002
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations forums :
    Inscription : Mars 2002
    Messages : 11
    Points : 38
    Points
    38
    Par défaut
    Voir le package SYS.DBMS_OBFUSCATION_LIB
    Source = $ORACLE_HOME/rdbms/admin/dbmsobtk.sql

    Il faut dans les préférence de l'administrateur sysman désigner une
    utilisateur windows du noeud du serveur oracle afin qu'il puisse ouvrir
    une session en tant que tache, il serait bien qu'il soit administrateur
    local.

    Voici l'exemple extrait de la doc Oracle
    "Oracle8i Supplied PL/SQL Packages Reference" :
    (c'est un peu long mais ça peut se révéler utile...)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
     
    DESEncryption and DESDecryption Code Example
    Following is a sample PL/SQL program for your reference. Segments of the
    code are numbered and contain narrative text explaining portions of the
    code.
     
    DECLARE
    input_string VARCHAR2(16) := 'tigertigertigert';
    raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(input_string);
    key_string VARCHAR2(8) := 'scottsco';
    raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(key_string);
    wrong_input_string VARCHAR2(25) := 'not_a_multiple_of_8_bytes';
    wrong_raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(wrong_input_string);
    wrong_key_string VARCHAR2(8) := 'scottsco';
    wrong_raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(wrong_key_string);
    encrypted_raw RAW(2048);
    encrypted_string VARCHAR2(2048);
    double_encrypted_raw RAW(2048);
    double_encrypted_string VARCHAR2(2048);
    decrypted_raw RAW(2048);
    decrypted_string VARCHAR2(2048);
    error_in_input_buffer_length EXCEPTION;
    PRAGMA EXCEPTION_INIT(error_in_input_buffer_length, -28232);
    INPUT_BUFFER_LENGTH_ERR_MSG VARCHAR2(100) :=
    '*** DES INPUT BUFFER NOT A MULTIPLE OF 8 BYTES - IGNORING EXCEPTION
    ***';
    double_encrypt_not_permitted EXCEPTION;
    PRAGMA EXCEPTION_INIT(double_encrypt_not_permitted, -28233);
    DOUBLE_ENCRYPTION_ERR_MSG VARCHAR2(100) :=
    '*** CANNOT DOUBLE ENCRYPT DATA - IGNORING EXCEPTION ***';
     
    -- 1. Begin testing raw data encryption and decryption
    BEGIN
    dbms_output.put_line('> ========= BEGIN TEST RAW DATA =========');
    dbms_output.put_line('> Raw input : ' ||
    UTL_RAW.CAST_TO_VARCHAR2(raw_input));
    BEGIN
    dbms_obfuscation_toolkit.DESEncrypt(input => raw_input,
    key => raw_key, encrypted_data => encrypted_raw );
    dbms_output.put_line('> encrypted hex value : ' ||
    rawtohex(encrypted_raw));
    dbms_obfuscation_toolkit.DESDecrypt(input => encrypted_raw,
    key => raw_key, decrypted_data => decrypted_raw);
    dbms_output.put_line('> Decrypted raw output : ' ||
    UTL_RAW.CAST_TO_VARCHAR2(decrypted_raw));
    dbms_output.put_line('> '); 
    if UTL_RAW.CAST_TO_VARCHAR2(raw_input) =
    UTL_RAW.CAST_TO_VARCHAR2(decrypted_raw) THEN
    dbms_output.put_line('> Raw DES Encyption and Decryption
    successful');
    END if;
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 2. Begin testing raw data double encryption prevention
    BEGIN
    dbms_output.put_line('> testing double encryption prevention');
    dbms_output.put_line('> ');
    dbms_obfuscation_toolkit.DESEncrypt(input => raw_input,
    key => raw_key, encrypted_data => encrypted_raw );
    dbms_output.put_line('> input hex value : ' ||
    rawtohex(encrypted_raw));
    dbms_obfuscation_toolkit.DESEncrypt(
    input => encrypted_raw,
    key => raw_key,
    encrypted_data => double_encrypted_raw );
    dbms_output.put_line('> double encrypted hex value : ' ||
    rawtohex(double_encrypted_raw));
    EXCEPTION
    WHEN double_encrypt_not_permitted THEN
    dbms_output.put_line('> ' || DOUBLE_ENCRYPTION_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 3. Begin testing wrong raw input length values for encrypt operation
    BEGIN
    dbms_output.put_line('> Wrong Raw input for encryption : ' ||
    UTL_RAW.CAST_TO_VARCHAR2(wrong_raw_input));
    dbms_obfuscation_toolkit.DESEncrypt(
    input => wrong_raw_input,
    key => raw_key,
    encrypted_data => encrypted_raw );
    dbms_output.put_line('> encrypted hex value : ' ||
    rawtohex(encrypted_raw));
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 4. Begin testing wrong raw input length values for decrypt operation
    BEGIN
    -- testing wrong input values for decyrpt operation
    dbms_output.put_line('> Wrong Raw input for decryption : ' ||
    UTL_RAW.CAST_TO_VARCHAR2(wrong_raw_input));
    dbms_obfuscation_toolkit.DESDecrypt
    (input => wrong_raw_input,
    key => raw_key,
    decrypted_data => decrypted_raw );
    dbms_output.put_line('> decrypted hex value : '
    || rawtohex(decrypted_raw));
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
    dbms_output.put_line('> ========= END TEST RAW DATA =========');
     
    -- 5. Begin testing string data encryption and decryption
    dbms_output.put_line('> ========= BEGIN TEST STRING DATA =========');
     
    BEGIN
    dbms_output.put_line('> input string : '
    || input_string);
    dbms_obfuscation_toolkit.DESEncrypt(
    input_string => input_string,
    key_string => key_string,
    encrypted_string => encrypted_string );
    dbms_output.put_line('> encrypted hex value : ' ||
    rawtohex(UTL_RAW.CAST_TO_RAW(encrypted_string)));
    dbms_obfuscation_toolkit.DESDecrypt(
    input_string => encrypted_string,
    key_string => key_string,
    decrypted_string => decrypted_string );
    dbms_output.put_line('> decrypted string output : ' ||
    decrypted_string);
    if input_string = decrypted_string THEN
    dbms_output.put_line('> String DES Encyption and Decryption
    successful');
    END if;
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line(' ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 6. Begin testing string data double encryption prevention
    BEGIN
    dbms_output.put_line('> testing double encryption prevention');
    dbms_output.put_line('> ');
    dbms_obfuscation_toolkit.DESEncrypt(
    input_string => input_string,
    key_string => key_string,
    encrypted_string => encrypted_string );
    dbms_output.put_line('> input hex value : ' ||
    rawtohex(UTL_RAW.CAST_TO_RAW(encrypted_string)));
    dbms_obfuscation_toolkit.DESEncrypt(
    input_string => encrypted_string,
    key_string => key_string,
    encrypted_string => double_encrypted_string );
    dbms_output.put_line('> double encrypted hex value : ' ||
    rawtohex(UTL_RAW.CAST_TO_RAW(double_encrypted_string)));
    EXCEPTION
    WHEN double_encrypt_not_permitted THEN
    dbms_output.put_line('> ' || DOUBLE_ENCRYPTION_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 7. Begin testing wrong string input length values for encyrpt operation
    BEGIN
    dbms_output.put_line('> testing wrong input values for encyrpt
    operation');
    dbms_output.put_line('> Wrong Raw input for encryption : ' ||
    wrong_input_string);
    dbms_obfuscation_toolkit.DESEncrypt(
    input_string => wrong_input_string,
    key_string => wrong_key_string,
    encrypted_string => encrypted_string );
    dbms_output.put_line('> encrypted hex value : ' ||
    rawtohex(UTL_RAW.CAST_TO_RAW(encrypted_string)));
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
     
    -- 8. Begin testing wrong string input length values for decrypt operation
    BEGIN
    -- testing wrong input values for decyrpt operation
    dbms_output.put_line('> Wrong Raw input for encryption : ' ||
    wrong_input_string);
    dbms_obfuscation_toolkit.DESDecrypt(
    input_string => wrong_input_string,
    key_string => wrong_key_string,
    decrypted_string => decrypted_string );
    dbms_output.put_line('> decrypted string output : ' ||
    decrypted_string);
    EXCEPTION
    WHEN error_in_input_buffer_length THEN
    dbms_output.put_line('> ' || INPUT_BUFFER_LENGTH_ERR_MSG);
    END;
    dbms_output.put_line('> ');
    dbms_output.put_line('> ========= END TEST STRING DATA =========');
    END;
    /

  3. #3
    Membre du Club
    Inscrit en
    Août 2002
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 37
    Points : 43
    Points
    43
    Par défaut
    Salut,

    Jette un oeil ici :
    http://www.developpez.net/forums/viewtopic.php?t=29779
    Si tu as besoin d'autres renseignement sur le cryptage n'hésites pas à m'en faire part .

    A+

  4. #4
    Membre du Club
    Inscrit en
    Août 2002
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 37
    Points : 43
    Points
    43
    Par défaut
    Et voici un exmeple de cryptage puisqu'a l'url que j'ai laissé ci dessus je ne traite que du decryptage :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    CREATE OR REPLACE PROCEDURE
    create_user(l_key in varchar2,
    	l_userid in varchar2,
    	l_nomprenom in varchar2,
    	l_tel in varchar2,
    	l_fax in varchar2,
    	l_site in number,	
    	l_log in varchar2,
    	l_service in number,
    	l_password in varchar2,)
    is
     
    l_data varchar2(2000);
    Key_check_flag number;
    l_encrypted_string varchar2(2000);
     
    BEGIN
                --- the key and the input data must have a length
     
                -- divisible by eight (the key must be exactly 8 bytes long).
     
                l_data := RPAD(l_password,(TRUNC(LENGTH(l_password)/8)+1)*8,CHR(0));
                key_check_flag := mod(length(l_key),8);
                      if key_check_flag != 0 then
                       Raise_application_error(-20199,'Key should be 8 char long');
                      end if;
                -- Encrypt the input string
                      DBMS_OBFUSCATION_TOOLKIT.DESENCRYPT
                         (input_string => l_data,
                         key_string => l_key,
                       encrypted_string => l_encrypted_string);
                -- DBMS_OUTPUT.PUT_LINE('l_string ENCRYPTED: ' || l_encrypted_string);
     
    insert into users 
    			(userid, nomprenom, tel, fax, site, date_creation, createur, service,password) values (LOWER(l_userid), UPPER(l_nomprenom), l_tel, l_fax, l_site, sysdate, l_log, l_service, l_encrypted_string);
    END;
    /

  5. #5
    yac
    yac est déconnecté
    Membre à l'essai
    Inscrit en
    Avril 2002
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 31
    Points : 17
    Points
    17
    Par défaut encrytpion de colonnes
    Bonjour,

    voila je suis en trai de faire l'analyse pour l'encryption d'une donnée(colonne ) sur une table. cette colonne est de type confidentiel.

    J'ai cherché sur le web et j'ai trouvé que je peut faire l'encryption et la decryption en utilisant la package dms_obfuscation, donc là kle problème ne se pose pas.


    Mon problème est que cette colonne est affichée dans un écran forms et elle est accéssible pour des usagers ayant le role necessaire. (elle est aussi inseré dans la bd via cet écran, l'encryption se fait via le trigger before insert de la table concernée)

    donc je voudrais savoir comment faire pour l'afficher decryptée dans cet écran ?
    - comment gérer toutes les mise à jour de champ qui est encrypté dans la table ?


    Merci.

  6. #6
    Membre éclairé Avatar de plabrevo
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    547
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 547
    Points : 670
    Points
    670
    Par défaut
    Le probleme de l'encryption, c'est la decryption. Si la valeur cryptee subsiste a proximite de la routine de decryption, on a rien resolu en terme de securite, exception faite d'un faux sentiment de securite accrue.

    Pourquoi dans le cas present ne pas conserver la colonne non cryptee, mais filtrer au contraire l'acces a la colonne en question avec VPD, cad la rendre visible en fonction des privileges dont beneficie l'utilisateur. Oracle10g permets le filtrage des donnees non seulement par enregistrement, mais egalement au niveau des colonnes.

  7. #7
    yac
    yac est déconnecté
    Membre à l'essai
    Inscrit en
    Avril 2002
    Messages
    31
    Détails du profil
    Informations forums :
    Inscription : Avril 2002
    Messages : 31
    Points : 17
    Points
    17
    Par défaut ENCRYPTION
    Bonjour,

    Ca semble trés interessant mais comment faire ?

    ou pourrais-je trouve plus de détails 6
    est ce c'est facile à mettre en place ?

    merci pour tout complément d'information.
    .

  8. #8
    Membre éclairé Avatar de plabrevo
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    547
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 547
    Points : 670
    Points
    670
    Par défaut
    Le mieux serait d'ouvrir un sujet sur VPD.

    Jetes un coup d'oeil sur http://www.oracle.com/technology/deploy/security/db_security/htdocs/vpd.html et sur la documentation concernant le package dbms_rls.

    VPD est extremement simple a implementer et a l'avantage d'etre relativement transparent pour l'application. Le principe consistera a attacher des 'policies' sur les tables a filtrer. Lors de l'execution, le noyau ajoutera automatiquement lors de chaque access a ces tables les elements de jointures correspondant a ces 'policies' (polices en francais?), ce en fonction du 'contexte' etabli pour la session. La principale difficulte reviendra a trouver le bon angle pour initializer ce contexte, en fonction des outils utilises (forms, jdbc, sql*plus, etc).

    Correction: Lien corrige (retire extra ',')

  9. #9
    Futur Membre du Club
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 6
    Points : 7
    Points
    7
    Par défaut
    Citation Envoyé par UbiK
    Salut,

    Jette un oeil ici :
    http://www.developpez.net/forums/viewtopic.php?t=29779
    Si tu as besoin d'autres renseignement sur le cryptage n'hésites pas à m'en faire part .

    A+

    de plus en plus de lien ne fontionnent plus sous developpez.net... c moyen quand meme ... comment on utilise ces petits script???

  10. #10
    Membre émérite Avatar de nuke_y
    Profil pro
    Indépendant en analyse de données
    Inscrit en
    Mai 2004
    Messages
    2 076
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Indépendant en analyse de données

    Informations forums :
    Inscription : Mai 2004
    Messages : 2 076
    Points : 2 370
    Points
    2 370
    Par défaut
    Bah un lien de 2002 en même temps...
    Il vaut mieux monopoliser son intelligence sur des bêtises que sa bêtise sur des choses intelligentes.

Discussions similaires

  1. [11gR2] Modifier l'ordre des colonnes d'une table sous Oracle
    Par doudou8mc dans le forum SQL
    Réponses: 7
    Dernier message: 07/11/2014, 14h57
  2. Réponses: 9
    Dernier message: 17/02/2009, 18h48
  3. Pas de JOIN sous Oracle (vraiment dommage...)
    Par Isildur dans le forum Langage SQL
    Réponses: 7
    Dernier message: 15/03/2007, 11h28
  4. Réponses: 15
    Dernier message: 05/09/2006, 09h53
  5. Supprimer une colonne sous SQL Serveur 2000
    Par WOLO Laurent dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 14/07/2003, 12h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo