├── .gitattributes ├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── as_crypto.sql ├── jwt.md └── test_as_crypto.sql /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sql linguist-detectable=true 2 | *.sql linguist-language=plsql 3 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://www.paypal.me/apexplugins/10'] 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 antonscheffer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # as_crypto 2 | A plsql implementation of some functions/procedures in dbms_crypto 3 | 4 | This does include 5 | * pkencrypt/pkdecrypt public/private key encryption/decryption with the following algorithms 6 | - RSA 7 | * sign/verify using 8 | - SHA224 RSA 9 | - SHA256 RSA RSA_X391 withECDSA withECDSAinP1363 10 | - SHA384 RSA RSA_X391 withECDSA withECDSAinP1363 11 | - SHA512 RSA RSA_X391 withECDSA withECDSAinP1363 12 | - SHA1 RSA RSA_X391 13 | * hash and mac function with the following algorithms 14 | - MD4 15 | - MD5 16 | - SH1 17 | - SH224 18 | - SH256 19 | - SH384 20 | - SH512 21 | - RIPEMD160 22 | * encrypt/decrypt of raw values with the following algorithms 23 | - DES 24 | - 3DES_2KEY 25 | - 3DES 26 | - AES128 27 | - AES192 28 | - AES256 29 | - RC4 30 | 31 | And this package can be used to create different types of JWT, for instance RS256, ES256 or HS256.
See https://github.com/antonscheffer/as_crypto/blob/master/jwt.md

32 | **Please note**: 33 | This package will soon be included in https://github.com/OraOpenSource/oos-utils 34 | ~~All additions, changes and bugfixes only will be available at that repository.~~ The package at OraOpenSource will be an "independent" fork. After several years only the hash functions are included, so I will continue to upgrade this package when needed. 35 | -------------------------------------------------------------------------------- /jwt.md: -------------------------------------------------------------------------------- 1 | You can use as_crypto to create or verify JWT's 2 | * ES256 3 | ~~~ 4 | declare 5 | l_header varchar2(1000); 6 | l_payload varchar2(1000); 7 | l_signature varchar2(1000); 8 | l_sign raw(1000); 9 | l_private_key varchar2(3999); 10 | l_public_key varchar2(3999); 11 | -- 12 | function base64URL_encode( p_src varchar2 ) 13 | return varchar2 14 | is 15 | begin 16 | return translate( utl_raw.cast_to_varchar2( utl_encode.base64_encode( p_src ) ), '+/= ' || chr(10) || chr(13), '-_' ); 17 | end; 18 | -- 19 | function base64URL_decode( p_txt varchar2 ) 20 | return raw 21 | is 22 | begin 23 | return utl_encode.base64_decode( utl_raw.cast_to_raw( translate( p_txt, '-_', '+/' ) ) ); 24 | end; 25 | begin 26 | l_header := base64URL_encode( utl_raw.cast_to_raw( '{"alg":"ES256","typ":"JWT"}' ) ); 27 | l_payload := base64URL_encode( utl_raw.cast_to_raw( '{"sub":"1234567890","name":"John Doe","admin":true,"iat":1516239022}' ) ); 28 | l_private_key := utl_raw.cast_to_raw( ' 29 | -----BEGIN PRIVATE KEY----- 30 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2 31 | OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r 32 | 1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G 33 | -----END PRIVATE KEY-----' ); 34 | l_public_key := utl_raw.cast_to_raw( ' 35 | -----BEGIN PUBLIC KEY----- 36 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEVs/o5+uQbTjL3chynL4wXgUg2R9 37 | q9UU8I5mEovUf86QZ7kOBIjJwqnzD1omageEHWwHdBO6B+dFabmdT9POxg== 38 | -----END PUBLIC KEY-----' ); 39 | l_sign := as_crypto.sign( utl_raw.cast_to_raw( l_header || '.' || l_payload ) 40 | , l_private_key 41 | , as_crypto.KEY_TYPE_EC 42 | , as_crypto.SIGN_SHA256withECDSAinP1363 43 | ); 44 | l_signature := base64URL_encode( l_sign ); 45 | dbms_output.put_line( l_signature ); 46 | if as_crypto.verify ( utl_raw.cast_to_raw( l_header || '.' || l_payload ) 47 | , base64URL_decode( l_signature ) 48 | , l_public_key 49 | , as_crypto.KEY_TYPE_EC 50 | , as_crypto.SIGN_SHA256withECDSAinP1363 51 | ) 52 | then 53 | dbms_output.put_line ('Verified'); 54 | else 55 | dbms_output.put_line ('Failed verification'); 56 | end if; 57 | end; 58 | ~~~ 59 | 60 | * RS256 61 | ~~~ 62 | declare 63 | l_header varchar2(1000); 64 | l_payload varchar2(1000); 65 | l_signature varchar2(1000); 66 | l_sign raw(1000); 67 | l_private_key varchar2(3999); 68 | l_public_key varchar2(3999); 69 | -- 70 | function base64URL_encode( p_src varchar2 ) 71 | return varchar2 72 | is 73 | begin 74 | return translate( utl_raw.cast_to_varchar2( utl_encode.base64_encode( p_src ) ), '+/= ' || chr(10) || chr(13), '-_' ); 75 | end; 76 | -- 77 | function base64URL_decode( p_txt varchar2 ) 78 | return raw 79 | is 80 | begin 81 | return utl_encode.base64_decode( utl_raw.cast_to_raw( translate( p_txt, '-_', '+/' ) ) ); 82 | end; 83 | begin 84 | l_header := base64URL_encode( utl_raw.cast_to_raw( '{"alg":"RS256","typ":"JWT"}' ) ); 85 | l_payload := base64URL_encode( utl_raw.cast_to_raw( '{"sub":"1234567890","name":"John Doe","admin":true,"iat":1516239022}' ) ); 86 | l_private_key := utl_raw.cast_to_raw( ' 87 | -----BEGIN PRIVATE KEY----- 88 | MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC7VJTUt9Us8cKj 89 | MzEfYyjiWA4R4/M2bS1GB4t7NXp98C3SC6dVMvDuictGeurT8jNbvJZHtCSuYEvu 90 | NMoSfm76oqFvAp8Gy0iz5sxjZmSnXyCdPEovGhLa0VzMaQ8s+CLOyS56YyCFGeJZ 91 | qgtzJ6GR3eqoYSW9b9UMvkBpZODSctWSNGj3P7jRFDO5VoTwCQAWbFnOjDfH5Ulg 92 | p2PKSQnSJP3AJLQNFNe7br1XbrhV//eO+t51mIpGSDCUv3E0DDFcWDTH9cXDTTlR 93 | ZVEiR2BwpZOOkE/Z0/BVnhZYL71oZV34bKfWjQIt6V/isSMahdsAASACp4ZTGtwi 94 | VuNd9tybAgMBAAECggEBAKTmjaS6tkK8BlPXClTQ2vpz/N6uxDeS35mXpqasqskV 95 | laAidgg/sWqpjXDbXr93otIMLlWsM+X0CqMDgSXKejLS2jx4GDjI1ZTXg++0AMJ8 96 | sJ74pWzVDOfmCEQ/7wXs3+cbnXhKriO8Z036q92Qc1+N87SI38nkGa0ABH9CN83H 97 | mQqt4fB7UdHzuIRe/me2PGhIq5ZBzj6h3BpoPGzEP+x3l9YmK8t/1cN0pqI+dQwY 98 | dgfGjackLu/2qH80MCF7IyQaseZUOJyKrCLtSD/Iixv/hzDEUPfOCjFDgTpzf3cw 99 | ta8+oE4wHCo1iI1/4TlPkwmXx4qSXtmw4aQPz7IDQvECgYEA8KNThCO2gsC2I9PQ 100 | DM/8Cw0O983WCDY+oi+7JPiNAJwv5DYBqEZB1QYdj06YD16XlC/HAZMsMku1na2T 101 | N0driwenQQWzoev3g2S7gRDoS/FCJSI3jJ+kjgtaA7Qmzlgk1TxODN+G1H91HW7t 102 | 0l7VnL27IWyYo2qRRK3jzxqUiPUCgYEAx0oQs2reBQGMVZnApD1jeq7n4MvNLcPv 103 | t8b/eU9iUv6Y4Mj0Suo/AU8lYZXm8ubbqAlwz2VSVunD2tOplHyMUrtCtObAfVDU 104 | AhCndKaA9gApgfb3xw1IKbuQ1u4IF1FJl3VtumfQn//LiH1B3rXhcdyo3/vIttEk 105 | 48RakUKClU8CgYEAzV7W3COOlDDcQd935DdtKBFRAPRPAlspQUnzMi5eSHMD/ISL 106 | DY5IiQHbIH83D4bvXq0X7qQoSBSNP7Dvv3HYuqMhf0DaegrlBuJllFVVq9qPVRnK 107 | xt1Il2HgxOBvbhOT+9in1BzA+YJ99UzC85O0Qz06A+CmtHEy4aZ2kj5hHjECgYEA 108 | mNS4+A8Fkss8Js1RieK2LniBxMgmYml3pfVLKGnzmng7H2+cwPLhPIzIuwytXywh 109 | 2bzbsYEfYx3EoEVgMEpPhoarQnYPukrJO4gwE2o5Te6T5mJSZGlQJQj9q4ZB2Dfz 110 | et6INsK0oG8XVGXSpQvQh3RUYekCZQkBBFcpqWpbIEsCgYAnM3DQf3FJoSnXaMhr 111 | VBIovic5l0xFkEHskAjFTevO86Fsz1C2aSeRKSqGFoOQ0tmJzBEs1R6KqnHInicD 112 | TQrKhArgLXX4v3CddjfTRJkFWDbE/CkvKZNOrcf1nhaGCPspRJj2KUkj1Fhl9Cnc 113 | dn/RsYEONbwQSjIfMPkvxF+8HQ== 114 | -----END PRIVATE KEY-----' ); 115 | l_public_key := utl_raw.cast_to_raw( ' 116 | -----BEGIN PUBLIC KEY----- 117 | MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1SU1LfVLPHCozMxH2Mo 118 | 4lgOEePzNm0tRgeLezV6ffAt0gunVTLw7onLRnrq0/IzW7yWR7QkrmBL7jTKEn5u 119 | +qKhbwKfBstIs+bMY2Zkp18gnTxKLxoS2tFczGkPLPgizskuemMghRniWaoLcyeh 120 | kd3qqGElvW/VDL5AaWTg0nLVkjRo9z+40RQzuVaE8AkAFmxZzow3x+VJYKdjykkJ 121 | 0iT9wCS0DRTXu269V264Vf/3jvredZiKRkgwlL9xNAwxXFg0x/XFw005UWVRIkdg 122 | cKWTjpBP2dPwVZ4WWC+9aGVd+Gyn1o0CLelf4rEjGoXbAAEgAqeGUxrcIlbjXfbc 123 | mwIDAQAB 124 | -----END PUBLIC KEY-----' ); 125 | l_sign := as_crypto.sign( utl_raw.cast_to_raw( l_header || '.' || l_payload ) 126 | , l_private_key 127 | , as_crypto.KEY_TYPE_RSA 128 | , as_crypto.SIGN_SHA256_RSA 129 | ); 130 | l_signature := base64URL_encode( l_sign ); 131 | dbms_output.put_line( l_signature ); 132 | if as_crypto.verify ( utl_raw.cast_to_raw( l_header || '.' || l_payload ) 133 | , base64URL_decode( l_signature ) 134 | , l_public_key 135 | , as_crypto.KEY_TYPE_RSA 136 | , as_crypto.SIGN_SHA256_RSA 137 | ) 138 | then 139 | dbms_output.put_line ('Verified'); 140 | else 141 | dbms_output.put_line ('Failed verification'); 142 | end if; 143 | end; 144 | ~~~ 145 | 146 | * HS256 147 | ~~~ 148 | l_payload varchar2(1000); 149 | l_signature varchar2(1000); 150 | l_sign raw(1000); 151 | l_secret raw(1000); 152 | -- 153 | function base64URL_encode( p_src varchar2 ) 154 | return varchar2 155 | is 156 | begin 157 | return translate( utl_raw.cast_to_varchar2( utl_encode.base64_encode( p_src ) ), '+/= ' || chr(10) || chr(13), '-_' ); 158 | end; 159 | -- 160 | function base64URL_decode( p_txt varchar2 ) 161 | return raw 162 | is 163 | begin 164 | return utl_encode.base64_decode( utl_raw.cast_to_raw( translate( p_txt, '-_', '+/' ) ) ); 165 | end; 166 | begin 167 | l_header := base64URL_encode( utl_raw.cast_to_raw( '{"alg":"HS256","typ":"JWT"}' ) ); 168 | l_payload := base64URL_encode( utl_raw.cast_to_raw( '{"sub":"1234567890","name":"John Doe","iat":1516239022}' ) ); 169 | l_secret := '571A910E9E061297F4A41FCDBF67C59DC2ABE04AA4FBFC166444B0FB3FF9498C'; 170 | dbms_output.put_line( base64URL_encode( l_secret ) ); -- use this encoded value in the jwt.io debugger and check "secret base64 encoded 171 | l_sign := as_crypto.mac( utl_raw.cast_to_raw( l_header || '.' || l_payload ) 172 | , as_crypto.HMAC_SH256 173 | , l_secret 174 | ); 175 | l_signature := base64URL_encode( l_sign ); 176 | dbms_output.put_line( l_signature ); 177 | end; 178 | ~~~ 179 | -------------------------------------------------------------------------------- /test_as_crypto.sql: -------------------------------------------------------------------------------- 1 | declare 2 | procedure test( p_secret raw, p_type pls_integer, p_key raw, p_iv raw, p_txt varchar2 ) 3 | is 4 | t_encr raw(32767); 5 | begin 6 | t_encr := as_crypto.encrypt( p_secret, p_type, p_key, p_iv ); 7 | if t_encr != dbms_crypto.encrypt( p_secret, p_type, p_key, p_iv ) 8 | then 9 | dbms_output.put_line( 'Difference encrypting ' || p_txt ); 10 | end if; 11 | if p_secret != as_crypto.decrypt( t_encr, p_type, p_key, p_iv ) 12 | then 13 | dbms_output.put_line( 'Difference decrypting ' || p_txt ); 14 | end if; 15 | end; 16 | -- 17 | procedure test_mac( p_src raw, p_type pls_integer, p_key raw, p_txt varchar2 ) 18 | is 19 | t_mac raw(3999); 20 | begin 21 | t_mac := as_crypto.mac( p_src, p_type, p_key ); 22 | if t_mac != dbms_crypto.mac( p_src, p_type, p_key ) 23 | then 24 | dbms_output.put_line( 'Difference for mac ' || p_txt ); 25 | end if; 26 | end; 27 | begin 28 | for i in 1 .. 18 29 | loop 30 | test( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 31 | , as_crypto.ENCRYPT_DES + as_crypto.CHAIN_CFB + as_crypto.PAD_NONE 32 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 33 | , null 34 | , 'DES + CFB + NONE' 35 | ); 36 | test( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 37 | , as_crypto.ENCRYPT_DES + as_crypto.CHAIN_CFB + as_crypto.PAD_PKCS5 38 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 39 | , null 40 | , 'DES + CFB + PKCS5' 41 | ); 42 | test( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 43 | , as_crypto.ENCRYPT_DES + as_crypto.CHAIN_CFB + as_crypto.PAD_ZERO 44 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 45 | , null 46 | , 'DES + CFB + ZERO' 47 | ); 48 | test( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 49 | , as_crypto.ENCRYPT_DES + as_crypto.CHAIN_CFB + as_crypto.PAD_ORCL 50 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 51 | , null 52 | , 'DES + CFB + ORCL' 53 | ); 54 | end loop; 55 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 56 | , as_crypto.ENCRYPT_DES + as_crypto.CHAIN_CFB + as_crypto.PAD_PKCS5 57 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 58 | , null 59 | , 'DES + CBC + PKCS5' 60 | ); 61 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 62 | , as_crypto.ENCRYPT_3DES_2KEY + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 63 | , utl_raw.cast_to_raw('1234567812345678') -- 16 bytes 64 | , null 65 | , '3DES_2KEY + CBC + PKCS5' 66 | ); 67 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 68 | , as_crypto.ENCRYPT_AES + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 69 | , utl_raw.cast_to_raw('1234567812345678') -- 16 bytes 70 | , null 71 | , 'AES + CBC + PKCS5, keylen 16' 72 | ); 73 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 74 | , as_crypto.ENCRYPT_AES + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 75 | , utl_raw.cast_to_raw('123456781234567812345678') -- 24 bytes 76 | , null 77 | , 'AES + CBC + PKCS5, keylen 24' 78 | ); 79 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 80 | , as_crypto.ENCRYPT_AES + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 81 | , utl_raw.cast_to_raw('12345678123456781234567812345678') -- 32 bytes 82 | , null 83 | , 'AES + CBC + PKCS5, keylen 32' 84 | ); 85 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 86 | , as_crypto.ENCRYPT_AES128 + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 87 | , utl_raw.cast_to_raw('1234567812345678') -- 16 bytes 88 | , null 89 | , 'AES128 + CBC + PKCS5' 90 | ); 91 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 92 | , as_crypto.ENCRYPT_AES192 + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 93 | , utl_raw.cast_to_raw('123456781234567812345678') -- 24 bytes 94 | , null 95 | , 'AES192 + CBC + PKCS5' 96 | ); 97 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 98 | , as_crypto.ENCRYPT_AES256 + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 99 | , utl_raw.cast_to_raw('12345678123456781234567812345678') -- 32 bytes 100 | , null 101 | , 'AES256 + CBC + PKCS5' 102 | ); 103 | test( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ) -- 19 bytes 104 | , as_crypto.ENCRYPT_3DES + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 105 | , utl_raw.cast_to_raw('1234567812345678ABCDEFGH') -- 24 bytes 106 | , null 107 | , '3DES + CBC + PKCS5' 108 | ); 109 | test( utl_raw.copies( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ), 15 ) -- 19 bytes * 15 110 | , as_crypto.ENCRYPT_3DES + as_crypto.CHAIN_CBC + as_crypto.PAD_PKCS5 111 | , utl_raw.cast_to_raw('1234567812345678ABCDEFGH') -- 24 bytes 112 | , '567812345678ABCD' -- 8 bytes 113 | , '3DES + CBC + PKCS5 + IV' 114 | ); 115 | test( utl_raw.copies( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ), 15 ) -- 19 bytes * 15 116 | , as_crypto.ENCRYPT_3DES + as_crypto.CHAIN_CFB + as_crypto.PAD_PKCS5 117 | , utl_raw.cast_to_raw('1234567812345678ABCDEFGH') -- 24 bytes 118 | , '567812345678ABCD' -- 8 bytes 119 | , '3DES + CFB + PKCS5 + IV' 120 | ); 121 | test( utl_raw.copies( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ), 15 ) -- 19 bytes * 15 122 | , as_crypto.ENCRYPT_3DES + as_crypto.CHAIN_ECB + as_crypto.PAD_PKCS5 123 | , utl_raw.cast_to_raw('1234567812345678ABCDEFGH') -- 24 bytes 124 | , '567812345678ABCD' -- 8 bytes 125 | , '3DES + ECB + PKCS5 + IV' 126 | ); 127 | test( utl_raw.copies( utl_raw.cast_to_raw( '12345678ABCDEFGHIJ' ), 15 ) -- 19 bytes * 15 128 | , as_crypto.ENCRYPT_3DES + as_crypto.CHAIN_OFB + as_crypto.PAD_PKCS5 129 | , utl_raw.cast_to_raw('1234567812345678ABCDEFGH') -- 24 bytes 130 | , '567812345678ABCD' -- 8 bytes 131 | , '3DES + OFB + PKCS5 + IV' 132 | ); 133 | -- 134 | for i in 1 .. 18 135 | loop 136 | test_mac( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 137 | , as_crypto.HMAC_MD5 138 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 139 | , 'MD5, size ' || i 140 | ); 141 | test_mac( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 142 | , as_crypto.HMAC_SH1 143 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 144 | , 'SH1, size ' || i 145 | ); 146 | $IF NOT DBMS_DB_VERSION.VER_LE_11 $THEN 147 | test_mac( utl_raw.substr( utl_raw.cast_to_raw( '0123456789ABCDEFGH987654321' ), 1, i ) 148 | , as_crypto.HMAC_SH256 149 | , utl_raw.cast_to_raw('12345678') -- 8 bytes 150 | , 'SH256, size ' || i 151 | ); 152 | $END 153 | end loop; 154 | dbms_output.put_line( 'Done' ); 155 | end; 156 | --------------------------------------------------------------------------------