How to generate aerospike key edigest from namespace,set,userkey without aerospike lib

To better understand how aerospike works I want to write a python script that generates the the key from namespace, set, and userkey.

I know that aerospike is using RIPEMD-160 hash and it looks like that for key generation it does not use namspace, but i wasn’t able to write python script that creates the same key as aerospike creates.

Here is the code example that is generating key with aerospike:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/usr/local/bin/python
import sys
import aerospike
config = {
'hosts': [ ('aerospike', 3000) ],
'policies': {"write": {"key": aerospike.POLICY_KEY_SEND}}
}
try:
client = aerospike.client(config).connect()
except:
print("Failed to connect to the cluster with", config['hosts'])
sys.exit(1)
key = ('test', 'demo', 'one')
print('key:', key)
try:
client.put(key, {'bin1': 'value1'})
except Exception as e:
print("error: {0}".format(e), file=sys.stderr)
sys.exit(1)
(key, metadata, record) = client.get(key)
print("key from aerospike:", key)
</code>
<code>#!/usr/local/bin/python import sys import aerospike config = { 'hosts': [ ('aerospike', 3000) ], 'policies': {"write": {"key": aerospike.POLICY_KEY_SEND}} } try: client = aerospike.client(config).connect() except: print("Failed to connect to the cluster with", config['hosts']) sys.exit(1) key = ('test', 'demo', 'one') print('key:', key) try: client.put(key, {'bin1': 'value1'}) except Exception as e: print("error: {0}".format(e), file=sys.stderr) sys.exit(1) (key, metadata, record) = client.get(key) print("key from aerospike:", key) </code>
#!/usr/local/bin/python

import sys
import aerospike

config = {
    'hosts': [ ('aerospike', 3000) ],
    'policies': {"write": {"key": aerospike.POLICY_KEY_SEND}}
}

try:
    client = aerospike.client(config).connect()
except:
    print("Failed to connect to the cluster with", config['hosts'])
    sys.exit(1)

key = ('test', 'demo', 'one')
print('key:', key)

try:
    client.put(key, {'bin1': 'value1'})
except Exception as e:
    print("error: {0}".format(e), file=sys.stderr)
    sys.exit(1)

(key, metadata, record) = client.get(key)
print("key from aerospike:", key)

This is the output of this script:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>root@d1716cafa3fb:/app# ./a.py
key: ('test', 'demo', 'one')
key from aerospike: ('test', 'demo', None, bytearray(b'xe4Ix9bJxa5r1fLxe0x19xe5xc2x9d"Xrxdbxbfx03'))
root@d1716cafa3fb:/app#
</code>
<code>root@d1716cafa3fb:/app# ./a.py key: ('test', 'demo', 'one') key from aerospike: ('test', 'demo', None, bytearray(b'xe4Ix9bJxa5r1fLxe0x19xe5xc2x9d"Xrxdbxbfx03')) root@d1716cafa3fb:/app# </code>
root@d1716cafa3fb:/app# ./a.py
key: ('test', 'demo', 'one')
key from aerospike: ('test', 'demo', None, bytearray(b'xe4Ix9bJxa5r1fLxe0x19xe5xc2x9d"Xrxdbxbfx03'))
root@d1716cafa3fb:/app#

And here is what I see in aerospike client after I execute this script:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>aql> set record_print_metadata true
RECORD_PRINT_METADATA = true
aql> select * from test
+-------+----------+--------------------------------+--------+---------+-------+
| PK | bin1 | {edigest} | {set} | {ttl} | {gen} |
+-------+----------+--------------------------------+--------+---------+-------+
| "one" | "value1" | "5EmbSqVyMWZM4Bnlwp0iWHLbvwM=" | "demo" | 2591964 | 1 |
+-------+----------+--------------------------------+--------+---------+-------+
1 row in set (0.024 secs)
</code>
<code>aql> set record_print_metadata true RECORD_PRINT_METADATA = true aql> select * from test +-------+----------+--------------------------------+--------+---------+-------+ | PK | bin1 | {edigest} | {set} | {ttl} | {gen} | +-------+----------+--------------------------------+--------+---------+-------+ | "one" | "value1" | "5EmbSqVyMWZM4Bnlwp0iWHLbvwM=" | "demo" | 2591964 | 1 | +-------+----------+--------------------------------+--------+---------+-------+ 1 row in set (0.024 secs) </code>
aql> set record_print_metadata true
RECORD_PRINT_METADATA = true
aql> select * from test
+-------+----------+--------------------------------+--------+---------+-------+
| PK    | bin1     | {edigest}                      | {set}  | {ttl}   | {gen} |
+-------+----------+--------------------------------+--------+---------+-------+
| "one" | "value1" | "5EmbSqVyMWZM4Bnlwp0iWHLbvwM=" | "demo" | 2591964 | 1     |
+-------+----------+--------------------------------+--------+---------+-------+
1 row in set (0.024 secs)

So for the namespace “test”, set “demo” and userkey “one” the base64 of key is “5EmbSqVyMWZM4Bnlwp0iWHLbvwM=”.

And here is my attempt to generate the same base64:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#!/usr/local/bin/python
from Crypto.Hash import RIPEMD
import base64
message = "demo one"
hash_obj = RIPEMD.new(data=message.encode('utf-8'))
hash_bytes = hash_obj.digest()
hash_base64 = base64.b64encode(hash_bytes).decode('utf-8')
print(f"RIPEMD-160 hash of '{message}' in base64 is: {hash_base64}")
</code>
<code>#!/usr/local/bin/python from Crypto.Hash import RIPEMD import base64 message = "demo one" hash_obj = RIPEMD.new(data=message.encode('utf-8')) hash_bytes = hash_obj.digest() hash_base64 = base64.b64encode(hash_bytes).decode('utf-8') print(f"RIPEMD-160 hash of '{message}' in base64 is: {hash_base64}") </code>
#!/usr/local/bin/python

from Crypto.Hash import RIPEMD
import base64

message = "demo one"

hash_obj = RIPEMD.new(data=message.encode('utf-8'))
hash_bytes = hash_obj.digest()
hash_base64 = base64.b64encode(hash_bytes).decode('utf-8')

print(f"RIPEMD-160 hash of '{message}' in base64 is: {hash_base64}")

This does not work. This output

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>root@d1716cafa3fb:/app# ./b.py
RIPEMD-160 hash of 'demo one' in base64 is: Lz0mUZgml2l+NLfnhwc+5RwlmEY=
</code>
<code>root@d1716cafa3fb:/app# ./b.py RIPEMD-160 hash of 'demo one' in base64 is: Lz0mUZgml2l+NLfnhwc+5RwlmEY= </code>
root@d1716cafa3fb:/app# ./b.py
RIPEMD-160 hash of 'demo one' in base64 is: Lz0mUZgml2l+NLfnhwc+5RwlmEY=

How can I modify my scrip so I get “5EmbSqVyMWZM4Bnlwp0iWHLbvwM=” ?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật