Skip to content

Commit

Permalink
Merge pull request ONDC-Official#52 from nishthamongaondc/main
Browse files Browse the repository at this point in the history
 Changes in naming convention
  • Loading branch information
92shreyansh authored Dec 28, 2023
2 parents 3c71da6 + c6b3120 commit 07fd00c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions utilities/on_subscibe-service/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ const crypto = require('crypto'); // Node.js crypto module for encryption and de
const _sodium = require('libsodium-wrappers');

const port = 3000; // Port on which the server will listen
const PRIVATE_KEY_1 =
const ENCRYPTION_PRIVATE_KEY =
'MC4CAQEwBQYDK2VuBCIEILgcht9h660ZeO36tG+QuHGNcLN9JuAzxHWZl09f57Bh';
const PUBLIC_KEY_1 =
const ONDC_PUBLIC_KEY =
'MCowBQYDK2VuAyEAlKHWJWiEiHFGlAJ6TE4VMGaeQUYg5DHEpuQdiq6flnQ=';
const REQUEST_ID = '6a6abf53-674f-4d6d-a52b-62e3fda55e04';
const SIGNING_PRIVATE_KEY =
Expand Down
8 changes: 4 additions & 4 deletions utilities/on_subscibe-service/node/readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

# Subscribing to ONDC Registry

1. Add following constants like below.

```
- PRIVATE_KEY_1 = "NP's encryption private key"
- PUBLIC_KEY_1 = "Registry's encryption public key which is available in NP On-Boarding on Staging doc (staging key: MCowBQYDK2VuAyEAduMuZgmtpjdCuxv+Nc49K0cB6tL/Dj3HZetvVN7ZekM=)"
- ENCRYPTION_PRIVATE_KEY = "NP's encryption private key"
- ONDC_PUBLIC_KEY = "Registry's encryption public key as per your environment which is available in NP On-Boarding on [document](https://github.com/ONDC-Official/developer-docs/blob/main/registry/Onboarding%20of%20Participants.md) (staging key: MCowBQYDK2VuAyEAduMuZgmtpjdCuxv+Nc49K0cB6tL/Dj3HZetvVN7ZekM=)"
- REQUEST_ID = "request_id which is sent in /subscribe"
- SIGNING_PRIVATE_KEY = "NP's signing private key"
```


2. Place the index.js file code into your main file, and this utility will host the on_subscribe endpoint as well as html file.
8 changes: 4 additions & 4 deletions utilities/signing_and_verification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ python cryptic_utils.py generate_key_pairs
```
Signing_private_key: G0Pme72u8Y1MwxHqvY4iBW+7VPtJ7dsX7SGs6zZ5yvVIzdRAyHR6YkwHG2ufOE+12lsbJRwBF4Hqd7dUEOZZkg==
Signing_public_key: SM3UQMh0emJMBxtrnzhPtdpbGyUcAReB6ne3VBDmWZI=
Crypto_Privatekey: MC4CAQAwBQYDK2VuBCIEIKi7NbXeN8QzXjN48XkjOiS/UaR6rumXep8VslMy4fRU
Crypto_Publickey: MCowBQYDK2VuAyEA9CEWxnLJkmwW/67QR739BEam7bbd3NsffjDa5HANf0Q=
Encryption_Privatekey: MC4CAQAwBQYDK2VuBCIEIKi7NbXeN8QzXjN48XkjOiS/UaR6rumXep8VslMy4fRU
Encryption_Publickey: MCowBQYDK2VuAyEA9CEWxnLJkmwW/67QR739BEam7bbd3NsffjDa5HANf0Q=
```

4. Export private and public keys
```
export PRIVATE_KEY=<private_key>
export PUBLIC_KEY=<public_key>
export CRYPTO_PRIVATE_KEY=<Crypto_Privatekey>
export CRYPTO_PUBLIC_KEY=<Crypto_Publickey>
export ENCRYPTION_PRIVATE_KEY=<Encryption_Privatekey>
export ENCRYPTION_PUBLIC_KEY=<Encryption_Publickey>
```

5. Create authorisation header
Expand Down
22 changes: 11 additions & 11 deletions utilities/signing_and_verification/cryptic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def generate_key_pairs():
#print(private_key)
public_key = base64.b64encode(bytes(signing_key.verify_key)).decode()
inst_private_key = X25519PrivateKey.generate()
#print(base64.b64encode(bytes(tcrypto_private_key.).decode()))
#print(base64.b64encode(bytes(tencryption_private_key.).decode()))
inst_public_key = inst_private_key.public_key()
bytes_private_key = inst_private_key.private_bytes(
encoding=serialization.Encoding.DER,
Expand All @@ -112,35 +112,35 @@ def generate_key_pairs():
encoding=serialization.Encoding.DER,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
crypto_private_key = base64.b64encode(bytes_private_key).decode('utf-8')
crypto_public_key = base64.b64encode(bytes_public_key).decode('utf-8')
encryption_private_key = base64.b64encode(bytes_private_key).decode('utf-8')
encryption_public_key = base64.b64encode(bytes_public_key).decode('utf-8')
return {"Signing_private_key": private_key,
"Signing_public_key": public_key,
"Crypto_Privatekey": crypto_private_key,
"Crypto_Publickey": crypto_public_key}
"Encryption_Privatekey": encryption_private_key,
"Encryption_Publickey": encryption_public_key}


def encrypt(crypto_private_key, crypto_public_key, null):
def encrypt(encryption_private_key, encryption_public_key, null):
private_key = serialization.load_der_private_key(
base64.b64decode(crypto_private_key),
base64.b64decode(encryption_private_key),
password=None
)
public_key = serialization.load_der_public_key(
base64.b64decode(crypto_public_key)
base64.b64decode(encryption_public_key)
)
shared_key = private_key.exchange(public_key)
cipher = AES.new(shared_key, AES.MODE_ECB)
text = b'ONDC is a Great Initiative!!'
return base64.b64encode(cipher.encrypt(pad(text,AES.block_size))).decode('utf-8')


def decrypt(crypto_private_key, crypto_public_key, cipherstring):
def decrypt(encryption_private_key, encryption_public_key, cipherstring):
private_key = serialization.load_der_private_key(
base64.b64decode(crypto_private_key),
base64.b64decode(encryption_private_key),
password=None
)
public_key = serialization.load_der_public_key(
base64.b64decode(crypto_public_key)
base64.b64decode(encryption_public_key)
)
shared_key = private_key.exchange(public_key)
cipher = AES.new(shared_key, AES.MODE_ECB)
Expand Down

0 comments on commit 07fd00c

Please sign in to comment.