라벨이 hashlib인 게시물 표시

파이썬[Python]: base64 - urlsafe_b64encode 함수

파이썬(Phthon): base64 모듈 urlsafe_b64encode 함수(function) /// 설명 URL이나 파일시스템에 안전한 문자를 사용하여 바이트 객체를 인코딩합니다. ('+' -> '-', '/' -> '_') ※ 형식 base64.urlsafe_b64encode(bytes) /// 예제 1 2 3 4 5 6 7 8 9 10 from  base64  import   *   # Base64 encoding test_str  =   'Is This a string0?' test_bytes  =  bytes(test_str,  'utf-8' ) test_encoded  =  urlsafe_b64encode(test_bytes)   print ( 'plain text    : '   +  test_str) print ( 'bytes         :' , test_bytes) print ( 'base64 encoded:' , test_encoded) cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - blake2s 메서드

hashlib 모듈 - blake2s 메서드(method) /// 설명 RFC 7693 에 정의되어 있는 암호화 해시 함수입니다. data: 해시를 적용할 메세지입니다. digest_size: 해시함수를 통해 반환되는 해시의 크기를 지정합니다. key: 해시함수에 적용할 비밀키입니다. salt: 난수를 사용하여 해시를 생성합니다. person: 다른 인자의 값이 같고, 해시의 목적이 다를 경우 사용합니다.(인자의 값이 같지 않아도 됩니다.) fanout: 참고사이트 depth: 참고사이트 leaf_size: 참고사이트 node_offset: 참고사이트 node_depth: 참고사이트 inner_size: 함수 내부에서 사용되는 digest 크기 last_node: 참고사이트 usedforsecurity: 제한적인 상황에서 안전하지 않을 경우 False를 이용할 수 있습니다. ※ 형식 hashlib.blake2s(data=b'', *, digest_size=32, key=b'', salt=b'', person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, node_depth=0, inner_size=0, last_node=False, usedforsecurity=True) reference https://docs.python.org/3/library/hashlib.html#module-hashlib /// 예제 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 import  os from  hashlib  import  blake2s   # RFC 7693

파이썬[Python]: hashlib - blake2b 메서드

hashlib 모듈 - blake2b 메서드(method) /// 설명 RFC 7693 에 정의되어 있는 암호화 해시 함수입니다. data: 해시를 적용할 메세지입니다. digest_size: 해시함수를 통해 반환되는 해시의 크기를 지정합니다. key: 해시함수에 적용할 비밀키입니다. salt: 난수를 사용하여 해시를 생성합니다. person: 다른 인자의 값이 같고, 해시의 목적이 다를 경우 사용합니다.(인자의 값이 같지 않아도 됩니다.) fanout: 참고사이트 depth: 참고사이트 leaf_size: 참고사이트 node_offset: 참고사이트 node_depth: 참고사이트 inner_size: 함수 내부에서 사용되는 digest 크기 last_node: 참고사이트 usedforsecurity: 제한적인 상황에서 안전하지 않을 경우 False를 이용할 수 있습니다. ※ 형식 hashlib.blake2b(data=b'', *, digest_size=64, key=b'', salt=b'', person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, node_depth=0, inner_size=0, last_node=False, usedforsecurity=True) reference https://docs.python.org/3/library/hashlib.html#module-hashlib /// 예제 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 import  os from  hashlib  import  blake2b   # RFC 7693

파이썬[Python]: hashlib - scrypt 메서드

hashlib 모듈 - scrypt 메서드(method) /// 설명 패스워드를 이용하여 키를 생성하는 scrypt 함수입니다. ※ 형식 hashlib.scrypt(password, *, salt, n, r, p) hashlib.scrypt(password, *, salt, n, r, p, maxmem=0, dklen=64) reference https://docs.python.org/3/library/hashlib.html#module-hashlib /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import  os import  hashlib   # RFC 7914 test_pass  =  b 'password'    # password test_salt  =  os.urandom( 16 )   # bytes test_n  =   8    # 1 < The CPU/Memory cost < 2^(128 * r / 8)(a power of 2 (e.g. 1024)) test_r  =   8    # block_size test_p  =   1    # 0 < The parallelization(CPU parallelism) <= ((2^32-1) * 32) / (128 * r) test_maxmem  =   0    # limitation of memory(OpenSSL 1.1.0 default 32MiB) test_dklen  =   16    # 0 < length of key <= (2^32 - 1) * 32   # producing a derived key test_key  =  hashlib.scrypt(test_pass, salt = test_salt, n = test_n, r = test_r, p = test_p) print (test_key) # b"R\xcdq\xb3\x99;\xa4

파이썬[Python]: hashlib - pbkdf2_hmac 메서드

hashlib 모듈 - pbkdf2_hmac 메서드(method) /// 설명 PKCS 시리즈(PKCS #5 v2.0) 중 하나로 패스워드를 이용하여 키를 생성하는 함수입니다. HMAC과 같은 유사난수 함수(pseudorandom function)를 적용하고 있습니다. 인자 dklen의 기본값은 사용하는 해시 함수의 digest_size 가 사용되어 집니다. ※ 형식 hashlib.pbkdf2_hmac(hash_name, password, salt, iterations) hashlib.pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None) /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import  os import  hashlib   test_name  =   'sha256' test_pass  =  b 'password' test_salt  =  os.urandom( 16 )   # bytes test_iter  =   100000    # iteration of algorithm   # producing a derived key test_key  =  hashlib.pbkdf2_hmac(test_name, test_pass, test_salt, test_iter) print (test_key)   # b"Q\xaa\xd8\xbd\xb2\x07\xab\xcf\xa72\x0c\xda\xdd\nw,\x89&'7\xe8P\xa9Q\x06\t\xae\xd4b\x19\xb8R" print (test_key.hex())   # 51aad8bdb207abcfa7320cdadd0a772c89262737e850a9510609aed46219b852   test_key  =  hashlib.pbkdf2_hmac(test_name, test_pass, test_salt, test_iter

파이썬[Python]: hashlib - hexdigest 메서드

hashlib 모듈 - hexdigest 메서드(method) /// 설명 update() 메서드에 의해 전달된 데이터의 결과(다이제스트 16진수 값)를 반환합니다. ※ 형식 shake.hexdigest(length) /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import  hashlib   test_hash  =  hashlib.new( 'shake_256' ) test_hash.update(b 'This is a string' )   print (test_hash.hexdigest( 20 ))   # b3ce77bb4c14ffa462ff4471d7bb0cd604be0270 print (test_hash.digest_size)   # 0 print (test_hash.block_size)   # 136   # The NIST standard # Output size d = digest_size # b = state_size = 1600 bit = 200 bytes # Rate r = block_size = 1088 bit = 136 bytes # Capacity c = b - r = 512 bit = 64 bytes # # Security strengths in bits = the number of operations # Collision ->        min(d/2, 256) # Preimage ->       >=min(d, 256) # 2nd Preimage ->     min(d, 256)   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - digest 메서드

hashlib 모듈 - digest 메서드(method) /// 설명 update() 메서드에 의해 전달된 데이터의 결과(다이제스트)를 반환합니다. ※ 형식 shake.digest(length) /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import  hashlib   test_hash  =  hashlib.new( 'shake_128' ) test_hash.update(b 'This is a string' )   print (test_hash.digest( 20 ))   # b'\xca\xb1?\xa3\x9d>\xec?[.T\xb1\x98\xbb<\xeb\xea\xa0=\x06' print (test_hash.digest_size)   # 0 print (test_hash.block_size)   # 168   # The NIST standard # Output size d = digest_size # b = state_size = 1600 bit = 200 bytes # Rate r = block_size = 1344 bit = 168 bytes # Capacity c = b - r = 256 bit = 32 bytes # # Security strengths in bits = the number of operations # Collision ->        min(d/2, 128) # Preimage ->       >=min(d, 128) # 2nd Preimage ->     min(d, 128) Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - copy 메서드

hashlib 모듈 - copy 메서드(method) /// 설명 해시 객체의 복사본("clone")을 반환합니다. ※ 형식 hash.copy() /// 예제 1 2 3 4 5 6 7 8 9 10 11 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.hexdigest())   # f72017485fbf6423499baf9b240daa14f5f095a1 print (test_hash)   # <sha1 _hashlib.HASH object @ 0x0000023408126BF0>   test_copy  =  test_hash.copy() print (test_copy.hexdigest())   # f72017485fbf6423499baf9b240daa14f5f095a1 print (test_copy)   # <sha1 _hashlib.HASH object @ 0x0000023408126BD0>   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - hexdigest 메서드

hashlib 모듈 - hexdigest 메서드(method) /// 설명 update() 메서드에 전달된 데이터의 결과(해시 함수에 적용한 16진수값)를 반환합니다. non-bianary환경에 사용되어 질 수 있습니다. ※ 형식 hash.hexdigest() /// 예제 1 2 3 4 5 6 7 8 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   print (test_hash.hexdigest())   # f72017485fbf6423499baf9b240daa14f5f095a1   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - digest 메서드

hashlib 모듈 - digest 메서드(method) /// 설명 update() 메서드에 전달된 데이터의 결과(해시 함수를 적용한 바이트 객체)를 반환합니다. ※ 형식 hash.digest() /// 예제 1 2 3 4 5 6 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - update 메서드

hashlib 모듈 - update 메서드(method) /// 설명 해시 알고리즘에 적용할 바이트 객체를 업데이트 합니다. hash.update(b'First string, ') hash.update(b'Second string') = hash.update(b'First string, Second string') ※ 형식 hash.update(data) /// 예제 1 2 3 4 5 6 7 8 9 10 11 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'First string, ' ) test_hash.update(b 'Second string' ) print (test_hash.digest())   # b'\xbc\x0b\xaeU\xb8w\x0e>\xedU\xfa\xdf\n\xa5K\xae2\xf6\xd2\xfe'   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'First string, Second string' ) print (test_hash.digest())   # b'\xbc\x0b\xaeU\xb8w\x0e>\xedU\xfa\xdf\n\xa5K\xae2\xf6\xd2\xfe'   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - name 변수

hashlib 모듈 - name 변수(variable) /// 설명 해시 알고리즘의 canonical name을 반환합니다. 이 이름은 항상 소문자이며 new() 매개변수로 적합합니다. ※ 형식 hash.name /// 예제 1 2 3 4 5 6 7 8 9 10 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.name)   # sha1   test_hash  =  hashlib.new( 'sha512' ) test_hash.update(b 'This is a string' ) print (test_hash.name)   # sha512   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - block_size 변수

hashlib 모듈 - block_size 변수(variable) /// 설명 해시 알고리즘이 내부에서 사용하는 블럭의 크기를 반환합니다.(Byte(s) - calculating) ※ 형식 hash.block_size /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.block_size)   # 64 print (test_hash.digest_size)   # 20 print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   test_hash  =  hashlib.new( 'sha512' ) test_hash.update(b 'This is a string' ) print (test_hash.block_size)   # 128 print (test_hash.digest_size)   # 64 print (test_hash.digest()) # b"\xf4\xd5M2\xe3R3W\xff\x029\x03\xea\xba'!\xe8\xc8\xcf\xc7p&cx,\xb3\xe5/\xaf,V\xc0\x02\xcc0\x96\xb5\xf2\xb6\xdf\x87\x0b\xe6e\xd0\x04\x0e\x99cY\x0e\xb0-\x03\xd1f\xe5)\x99\xcd\x1cC\r\xb1"   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - digest_size 변수

hashlib 모듈 - digest_size 변수(variable) /// 설명 해시 알고리즘에 의해 표현된 결과의 크기를 반환합니다.(Byte(s) - result) ※ 형식 hash.digest_size /// 예제 1 2 3 4 5 6 7 import  hashlib   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.digest_size)   # 20 print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - algorithms_available 변수

hashlib 모듈 - algorithms_available 변수(variable) /// 설명 파이썬 인터프리터에서 사용되고 있는 해시 알고리즘들을 반환합니다. ※ 형식 hashlib.algorithms_available /// 예제 1 2 3 4 5 6 7 8 import  hashlib   print (hashlib.algorithms_available) # {'ripemd160', 'sha512', 'blake2s', 'sm3', 'whirlpool', 'md5', # 'sha1', 'sha256', 'shake_128', 'shake_256', 'md5-sha1', 'sha3_512', # 'mdc2', 'sha224', 'sha3_224', 'md4', 'blake2b', 'sha3_384', # 'sha512_256', 'sha3_256', 'sha512_224', 'sha384'}   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - algorithms_guaranteed 변수

hashlib 모듈 - algorithms_guaranteed 변수(variable) /// 설명 모든 플랫폼에서 사용가능한 모듈로 보증된 해시 알고리즘들을 반환합니다. ※ 형식 hashlib.algorithms_guaranteed /// 예제 1 2 3 4 5 6 7 import  hashlib   print (hashlib.algorithms_guaranteed) # {'blake2s', 'sha1', 'sha512', 'shake_256', 'blake2b', 'sha384', # 'md5', 'sha3_256', 'shake_128', 'sha224', 'sha3_512', 'sha3_384', # 'sha256', 'sha3_224'}   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Python 3.9) – 당신을 응원합니다. –

파이썬[Python]: hashlib - new 클래스

hashlib 모듈 - new 클래스(class) /// 설명 첫번째 인자로 사용하고자 하는 해시 알고리즘을 명시하는 제네릭한 생성자 입니다. 두번째 인자는 메세지 다이제스트를 얻고자 하는 정보이며, 세번째 인자는 기본값은 True 입니다. 제한적인 상황에서 안전하지 않으며 사용이 금지된 해시 알고리즘을 사용할 경우 False를 이용할 수 있습니다. ※ 형식 hashlib.new(name) hashlib.new(name, data) hashlib.new(name, data, *, usedforsecurity=True) /// 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 import  hashlib   test_hash  =  hashlib.sha1() test_hash.update(b 'This is a string' ) print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   test_hash  =  hashlib.new( 'sha1' ) test_hash.update(b 'This is a string' ) print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   test_hash  =  hashlib.new( 'sha1' , b 'This is a string' ) print (test_hash.digest())   # b'\xf7 \x17H_\xbfd#I\x9b\xaf\x9b$\r\xaa\x14\xf5\xf0\x95\xa1'   Colored by Color Scripter cs * 실행환경: Microsoft Windows 10 Homes * 인터프리터: 파이썬(Py