23 พฤศจิกายน 2563

Investigate ObjectId (_id) of MongoDB

ObjectId (_id) of MongoDB is an auto-generated primary key by MongoDB. 


This field consists of 3 parts

1. a 4-byte timestamp value, representing the ObjectId’s creation, measured in seconds since the Unix epoch

2. a 5-byte random value

3. a 3-byte incrementing counter, initialized to a random value


e.g., 5fbb912a5eeb8beee934a5c4

1. timestamp value is 5fbb912a, we can get the creation time by using any computer language to perform basic calculation


2. random value is 5eeb8beee9


3. increasing counter value is 34a5c4

I tried to add more document and get these ObjectIds (_id) consecutively

5fbb91275eeb8beee934a5c0

5fbb91285eeb8beee934a5c1

5fbb91285eeb8beee934a5c2

5fbb91295eeb8beee934a5c3

You can see that the last part of each ObjectId (_id) is increment one by one.

Encrypt and decrypt data with Google Cloud KMS (Asymmetric)

Follow this tutorial if you want to use Google Managed Key on Google Cloud KMS.

But if you want to create your own key and upload it to Google Cloud KMS, please follow these steps

Generate key in der format

openssl genrsa -out key-pri.pem 3072

openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER \
-in key-pri.pem \
-out key-pri.der

openssl rsa -in key-pri.pem -pubout -out key-pub.pem


Upload key (.der file) to Google Cloud KMS

gcloud kms import-jobs create job \
--project ${PROJECT_ID} \
--location global \
--keyring ${KEY_RING} \
--import-method rsa-oaep-3072-sha1-aes-256 \
--protection-level software

gcloud kms keys versions import \
--project ${PROJECT_ID} \
--import-job job \
--location global \
--keyring ${KEY_RING} \
--key key \
--algorithm rsa-decrypt-oaep-3072-sha256 \
--target-key-file key.der

*you need to install crypto first


13 พฤศจิกายน 2563

SSL certificate server test online, SSL certificate server analysis online, View Server SSL certificate online

You can test your SSL certificate server online using a link to verify whether your server is secure enough or not and also view your SSL server information.





บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (1 ปีย้อนหลัง)