By b00m.kl on Tag:

ผมรบกวนขอคำแนะนำวิธีส่งออก RSA PRIVATE KEY ไฟล์ จากไฟล์ cert ( ไม่แน่ใจว่าต้องใช้ไฟล์ cert นามสกุลอะไร)

Hiring! บริษัทที่น่าสนใจ

Carmen Software company cover
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd. company cover
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime company cover
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group company cover
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies company cover
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand company cover
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software company cover
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE company cover
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud company cover
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise company cover
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank company cover
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank company cover
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.) company cover
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd. company cover
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group company cover
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited company cover
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd. company cover
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV company cover
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB company cover
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd. company cover
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH company cover
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks company cover
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd. company cover
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech company cover
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd company cover
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand company cover
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai company cover
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand

รบกวนสอบถามครับ คือ ไฟล์ต้นทางต้องเป็นไฟล์ นามสกุลอะไรครับ เช่น .cer, .crt แล้วเรา copy เนื้อหาข้างในมาใส่ใน ไฟล์ RSA PRIVATE KEY ได้เลยหรือครับ (ใส่ระหว่าง -----BEGIN RSA PRIVATE KEY----- และ -----END RSA PRIVATE KEY----- ใช่ไหมครับ) แล้วใช้งานได้เลยนะครับ

extension ไม่สำคัญครับ
อยู่ที่ program จะใช้ key มันต้องการนามสกุลเจาะจงหรือเปล่า

เวลา copy ก็ copy content ใน file ทั้งหมดหรือ copy ทั้ง file ก็ได้ครับไป rename เอา

ว่าแต่จะ copy private key ไปทำอะไรครับ
private key ปกติมันไม่ต้อง copy บ่อย ส่วนมากจะ generate ใหม่เอาเลย

ขอบคุณครับ ผมมีเขียนโปรแกรมติดต่อกับทางธนาคารครับ โดยส่งเป็นข้อความ พร้อมกับมีการ Signature ป้องกันข้อมูลครับ แต่ปัญหาคือ ผม signature ไปแล้ว ธนาคารตรวจสอบว่าไม่ถูกต้องครับ

ธนาคารขอ private key เองหรือใครขอครับ
ปกติคนที่ใช้ private key sign/encode code challenge จะเก็บไว้เองไม่ให้ใครครับ
ที่ให้ได้คือ public key มันใช้ decode ได้อย่างเดียว (private key ใช้ encode ,decode, generate public key ได้)

แต่ถ้าใช้ encode ข้อความ ส่งหากันก็ ok

คือทางธนาคาร แนะนำให้ทำการ sing ข้อความ ตามตัวอย่างจากเว็บ นี้

https://8gwifi.org/RSAFunctionality?rsasignverifyfunctions=rsasignverifyfunctions&keysize=512

และผมใช้ python ในการทำการ encrytp ดังนี้

# -*- coding: utf-8 -*-

#from base64 import (b64encode, b64decode)
import base64
import json
from Crypto.Hash import SHA256
from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA

message = '{"serv": "REAPI","Value": "5057", "amount": "71.10"}'

print("message > ")
print(message)

digest = SHA256.new()
digest.update(message.encode('utf-8'))
private_key_file_pem = "./cert/RSA_PrivateKey.txt"
# Load private key previouly generated
with open(private_key_file_pem, "r") as myfile:
private_key = RSA.importKey(myfile.read())

# Sign the message
print(f"private_key > {private_key}")

signature = PKCS1_v1_5.new(private_key).sign(digest)
result = base64.b64encode(signature).decode()
print(f"signature > {signature}")
print("Signature base64 :")
print(result)

คือ ผลที่ได้เอาไปเปรียบเทียบกับเว็บ https://8gwifi.org/RSAFunctionality ตรงกันครับ แต่ปัญหาคือ ส่งไปให้ธนาคาร ธนาคาร บอกไม่ตรง ซึ่งน่าจะเป็นไฟล์ RSA_PrivateKey.txt ที่สร้างมาให้ผมใช้ คนสร้างก็ไม่รู้ว่าสร้างมาจากไหน ผมอยากหาวิธีสร้างไฟล์ RSA_PrivateKey.txt ด้วยตัวเอง แล้วทดสอบเพื่อไปยืนยันกับคนสร้างไฟล์ RSA_PrivateKey.txt ว่าไฟล์ RSA_PrivateKey.txt ที่คุณให้ผมมาไม่ตรงกับไฟล์ cert ที่ใช้อยู่ของบริษัท

และผมลองไปหาวิธีสร้างเอง ได้ดังนี้

openssl pkcs12 -in Cert66.pfx -nocerts -out Cert66.key

openssl pkcs12 -in Cert66.pfx -clcerts -nokeys -out Cert66.crt

openssl rsa -in Cert66.key -out RSA_PrivateKey.txt

แต่ไฟล์ RSA_PrivateKey.txt กลับใช้งานไม่ได้ครับ ผมไม่แน่ใจว่าผมสร้างผิดหรือเปล่า เพราะเนื้อหาในไฟล์ที่ได้แปะหัวมาเป็น แค่ -----BEGIN PRIVATE KEY----- ไม่ใช่แบบเดิม คือ -----BEGIN RSA PRIVATE KEY----- เลยยิ่งงงมาเลยครับ ติดมานานแล้วด้วยแก้ไม่ได้ ไปต่อก็งง

variable message นี่คือข้อความที่ธนาคารส่งมาให้คุณ sign แล้วส่งกลับหรือเปล่าครับ?
ถ้าใช่ผมว่ากระบวนการน่าจะผิดบางอย่าง

-ที่ธนาคารต้องการน่าจะเป็น public key มากกว่า (ดูจากตัวอย่างที่ธนาคารให้มา) ส่วนจะทำหา public key อย่างไร https://www.digicert.com/kb/ssl-support/openssl-quick-reference-guide.htm#ExtractingYourPublicKey อย่าไปอ่านเกิน

-ถ้า variable message คือ code challenge ที่ส่งมาจากธนาคาร มันน่าจะเป็น base64 urlsafe ครับ อาจจะต้อง decode ก่อนเอาไป sign (เวลาส่งกลับก็ควร encode base64 urlsafe ด้วยนะครับ)

-เวลาธนาคาร verify เขาน่าจะเอา message ที่ส่งให้คุณเทียบกับกับ signature ที่ decode โดย public key ครับ คุณสามารถใช้ key ที่จะส่งให้ธนาคารลอง decode signature เพื่อ check ดูได้ครับ

ต้องลอง check protocol ของธนาคารดูอีกทีครับ ผมเองก็ไม่แน่ใจที่ตอบไปอยู่