Advertisement
peter9477

AES encryption via Python 3.2 ctypes on BB10

Oct 8th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | None | 0 0
  1. >>> from ctypes import *
  2. >>> dll = CDLL('libhuapi.so')
  3. >>> ctx = c_void_p()
  4. >>> dll.hu_GlobalCtxCreateDefault(byref(ctx))
  5. 0
  6. >>> ctx
  7. c_void_p(2030254944)
  8. >>> dll.hu_RegisterSbg56(ctx)
  9. 0
  10. >>> dll.hu_RegisterSystemSeed(ctx)
  11. 0
  12. >>> dll.hu_InitSbg56(ctx)
  13. 0
  14. >>> params = c_void_p()
  15. >>> dll.hu_AESParamsCreate(1, 128, None, None, byref(params), ctx)
  16. 0
  17. >>> params
  18. c_void_p(2039413424)
  19. >>> key = c_void_p()
  20. >>> dll.hu_AESKeySet(params, len('M02cnQ51Ji97vwT4')*8, b'M02cnQ51Ji97vwT4', byref(key), ctx)
  21. 0
  22. >>> key
  23. c_void_p(2039415368)
  24. >>> plain = b'`Twas brillig, and the slithy toves did gyre and gimble in the wabe.'
  25. >>> len(plain) % 16
  26. 4
  27. >>> plain += b'\x0c' * 12
  28. >>> plain
  29. b'`Twas brillig, and the slithy toves did gyre and gimble in the wabe.\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c'
  30. >>> out = create_string_buffer(len(plain))
  31. >>> out
  32. <ctypes.c_char_Array_80 object at 0x790fdb70>
  33. >>> iv = create_string_buffer(16)
  34. >>> iv
  35. <ctypes.c_char_Array_16 object at 0x790fdb20>
  36. >>> len(iv)
  37. 16
  38. >>> dll.hu_AESEncryptMsg(params, key, 16, iv, len(plain), plain, out, ctx)
  39. 0
  40. >>> bytes(out)
  41. b"\x04\xd1\xff\xb2N:\xc8\xbezC\xef\xb7F\xcd\xa0%\x7f|eYm\xd90j`\xb1\x0c\xb8\x83=\x91n\xbf\xf8D\xdcD\xe4\x82'\xcc\xba\xef\xd1=\xa9\xdb!5\x18D\xc7&\xfeR\xa6\xfb\x7f\x00\x13\xbfj\xd2\x96zL\xba\xc4\xb2\x9a\xe2\x99\xde\xb8y\xa5\xe0\x7f\xef\x9f"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement