日本熟妇hd丰满老熟妇,中文字幕一区二区三区在线不卡 ,亚洲成片在线观看,免费女同在线一区二区

密碼算法相關(guān)

本文為您介紹密碼算法相關(guān)函數(shù)的語法、說明、參數(shù)、返回值和示例。

aes_new

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

aes_new(config)

說明

創(chuàng)建AES對(duì)象,用于后續(xù)的aes_enc()加密和aes_dec()解密。

參數(shù)

config參數(shù)為字典類型,包含如下參數(shù):

  • (必選)key:密鑰,字符串類型。

  • (可選)salt:鹽值,字符串類型。

  • (必選)cipher_len:密碼器長(zhǎng)度。取值范圍:128、192和256。

  • (必選)cipher_mode:密碼器模式。取值范圍:ecb、cbc、ctr、cfb和ofb。

  • (可選)iv:初始向量,字符串類型。

返回值

成功返回AES對(duì)象(字典類型),失敗返回false

示例

aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  set(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  set(aes_conf, 'salt', '1234567890')                                                                                                                                               
  set(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  set(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  set(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

aes_enc

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

aes_enc(o, s)

說明

AES加密。

參數(shù)

  • s:明文或密文。

  • o:表示aes_new返回的AES對(duì)象。

返回值

返回對(duì)s加密后的密文。

示例

aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  set(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  set(aes_conf, 'salt', '1234567890')                                                                                                                                               
  set(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  set(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  set(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

aes_dec

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

aes_dec(o, s)

說明

AES解密。

參數(shù)

  • s:密文。

  • o:表示aes_new返回的AES對(duì)象。

返回值

返回對(duì)s解密后的明文。

示例

aes_conf = []                                                                                                                                                                         
plaintext = ''                                                                                                                                                                        
if and($http_mode, eq($http_mode, 'ecb-128')) {                                                                                                                                       
  set(aes_conf, 'key', 'ab8bfd9f-a1af-4ba2-bbb0-1ee520e3d8bc')                                                                                                                      
  set(aes_conf, 'salt', '1234567890')                                                                                                                                               
  set(aes_conf, 'cipher_len', 128)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ecb')                                                                                                                                               
  plaintext = 'hello aes ecb-128'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'cbc-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'cbc')                                                                                                                                               
  set(aes_conf, 'iv', '0123456789abcdef')                                                                                                                                           
  plaintext = 'hello aes cbc-256'                                                                                                                                                   
}                                                                                                                                                                                     
if and($http_mode, eq($http_mode, 'ofb-256')) {                                                                                                                                       
  set(aes_conf, 'key', '146ebcc8-392b-4b3a-a720-e7356f62')                                                                                                                          
  set(aes_conf, 'cipher_len', 256)                                                                                                                                                  
  set(aes_conf, 'cipher_mode', 'ofb')                                                                                                                                               
  set(aes_conf, 'iv', tochar(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))                                                                                                                      
  plaintext = 'hello aes ofb-256'                                                                                                                                                   
}                                                                                                                                                                                     

aes_obj = aes_new(aes_conf)                                                                                                                                                           
if not(aes_obj) {                                                                                                                                                                     
  say(concat('aes obj failed'))                                                                                                                                                     
  exit(400)                                                                                                                                                                         
}                                                                                                                                                                                     

ciphertext = aes_enc(aes_obj, plaintext)                                                                                                                                              
plaintext_reverse = aes_dec(aes_obj, ciphertext)                                                                                                                                      

say(concat('plain: ', plaintext))                                                                                                                                                     
say(concat('cipher: ', tohex(ciphertext)))                                                                                                                                            
say(concat('plain_reverse: ', plaintext_reverse))                                                                                                                                     

if ne(plaintext, plaintext_reverse) {                                                                                                                                                 
  say('plaintext ~= plaintext_reverse')                                                                                                                                            
  exit(400)                                                                                                                                                                        
}

sha1

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

sha1(s)

說明

計(jì)算SHA1摘要。

參數(shù)

s:待計(jì)算摘要的字符串。

返回值

返回SHA1摘要的二進(jìn)制形式。

示例

digest = sha1('hello sha')                                                                                                                                                        
say(concat('sha1:', tohex(digest)))

輸出:
sha1:853789bc783a6b573858b6cc9f913afe82962956

sha2

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

sha2(s, l)

說明

計(jì)算SHA2摘要。

參數(shù)

  • s:待計(jì)算摘要的字符串。

  • l:指明SHA2長(zhǎng)度。取值范圍:224、256、384和512。

返回值

使用SHA2摘要的二進(jìn)制形式。

示例

digest = sha2('hello sha2', 224)
say(concat('sha2-224:', tohex(digest)))

digest = sha2('hello sha2', 256)
say(concat('sha2-256:', tohex(digest)))

digest = sha2('hello sha2', 384)
say(concat('sha2-384:', tohex(digest)))

digest = sha2('hello sha2', 512)
say(concat('sha2-512:', tohex(digest)))

輸出:
sha2-224:b24b7effcf53ce815ee7eb73c7382613aba1c334e2a1622655362927
sha2-256:af0425cee23c236b326ed1f008c9c7c143a611859a11e87d66d0a4c3217c7792
sha2-384:bebbdde9efabd4b9cf90856cf30e0b024dd13177d9367d2dcf8d7a04e059f92260f16b21e261358c2271be32086ef35b
sha2-512:a1d1aef051c198c0d26bc03500c177a315fa248cea815e04fbb9a75e5be5061617daab311c5e3d0b215dbfd4e83e73f23081242b0143dcdfce5cd92ec51394f7

hmac

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

hmac(k, s, v)

說明

計(jì)算HMAC類算法摘要。

參數(shù)

  • k:算法密鑰。

  • s:待計(jì)算摘要的字符串。

  • v:算法版本。取值范圍: md5、sha1、sha256和sha512。

返回值

使用對(duì)應(yīng)算法HMAC摘要的二進(jìn)制形式。

示例

k = '146ebcc8-392b-4b3a-a720-e7356f62f87b'
v = 'hello mac'
say(concat('hmac(md5): ', tohex(hmac(k, v, 'md5'))))
say(concat('hmac(sha1): ', tohex(hmac(k, v, 'sha1'))))
say(concat('hmac(sha256): ', tohex(hmac(k, v, 'sha256'))))
say(concat('hmac(sha512): ', tohex(hmac(k, v, 'sha512'))))
say(concat('hmac_sha1(): ', tohex(hmac_sha1(k, v))))

輸出:
hmac(md5): 358cbfca8ad663b547c83748de2ea778
hmac(sha1): 5555633cef48c3413b68f9330e99357df1cc3d93
hmac(sha256): 7a494543cad3b92ce1e7c4bbc86a8f5212b53e4d661f7830f455847540a85771
hmac(sha512): 59d7c07996ff675b45bd5fd40a6122bb5f40f597357a9b4a9e29da6f5c7cb806798c016fe09cb46457b6df9717d26d0af19896f72eaf4296be03e3681fea59ad
hmac_sha1(): 5555633cef48c3413b68f9330e99357df1cc3d93

hmac_sha1

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

hmac_sha1(k, s)

說明

計(jì)算HMAC-SHA-1摘要。

參數(shù)

  • s:待計(jì)算摘要的字符串。

  • k:HMAC-SHA-1密鑰。

返回值

返回HMAC-SHA-1摘要的二進(jìn)制形式。

示例

k = '146ebcc8-392b-4b3a-a720-e7356f62f87b'
v = 'hello mac'
say(concat('hmac(md5): ', tohex(hmac(k, v, 'md5'))))
say(concat('hmac(sha1): ', tohex(hmac(k, v, 'sha1'))))
say(concat('hmac(sha256): ', tohex(hmac(k, v, 'sha256'))))
say(concat('hmac(sha512): ', tohex(hmac(k, v, 'sha512'))))
say(concat('hmac_sha1(): ', tohex(hmac_sha1(k, v))))

輸出:
hmac(md5): 358cbfca8ad663b547c83748de2ea778
hmac(sha1): 5555633cef48c3413b68f9330e99357df1cc3d93
hmac(sha256): 7a494543cad3b92ce1e7c4bbc86a8f5212b53e4d661f7830f455847540a85771
hmac(sha512): 59d7c07996ff675b45bd5fd40a6122bb5f40f597357a9b4a9e29da6f5c7cb806798c016fe09cb46457b6df9717d26d0af19896f72eaf4296be03e3681fea59ad
hmac_sha1(): 5555633cef48c3413b68f9330e99357df1cc3d93

md5

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

md5(s)

說明

計(jì)算MD5摘要。

參數(shù)

s:待計(jì)算摘要的字符串。

返回值

返回MD5摘要的十六進(jìn)制形式。

示例

say(concat('md5: ', md5('hello md5')))

輸出:
md5: 741fc6b1878e208346359af502dd11c5

md5_bin

函數(shù)詳細(xì)信息,請(qǐng)參見下表:

項(xiàng)目

描述

語法

md5_bin(s)

說明

計(jì)算MD5摘要。

參數(shù)

s:待計(jì)算摘要的字符串。

返回值

返回MD5摘要的二進(jìn)制形式。

示例

say(concat('md5_bin: ', tohex(md5_bin('hello md5'))))

輸出:
md5_bin: 741fc6b1878e208346359af502dd11c5