PC-Logix / OpenSecurity

Security addon for OpenComputers
MIT License
47 stars 24 forks source link

[Bug] Card writer dosen't write accurate data #146

Closed Asmoyed closed 4 years ago

Asmoyed commented 4 years ago

Describe the bug Mag card data write dosen't work, I'm trying to write encoded data with the component data from OC, but the data on the does not match the result from the encryption function

In which environment did the Bug appear? Singleplayer

To Reproduce Encrypt a string with OC encrypt function Write the result onto a mag card Read the data of the card Result and card data arent equal

Expected behavior The encrypted data should be properly written onto the card

Screenshots / Code Snippet

component = require("component")
writer = component.os_cardwriter
data = component.data
reader = component.os_magreader
key = data.random(128)
iv = data.random(16)
writer.write(data.encrypt("test",key,iv),"Test Card")
_, _, _, cardData = event.pull("magData")
print(cardData == (data.encrypt("test",key,iv))

image

Minecraft:

Additional context Nothing more to say

ben-mkiv commented 4 years ago

The cardwriter writes Strings while the data component probably returns an byte Array. Cant really test it right now as your test script wont work for me at all.

Could you try to convert the data with component.data.encode64(data) before writing it and decoding it after reading with component.data.decode64(data) that might work around the issue

Asmoyed commented 4 years ago

It seems to be working Thanks ^^

ben-mkiv commented 4 years ago

added this information to the wiki https://github.com/PC-Logix/OpenSecurity/wiki/CardWriter#binary-data

Closing this as it seems to be resolved.