Fanatic Live: reencrypting file - Fanatic Live

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

reencrypting file Rate Topic: -----

#1 User is offline   The_Huuf

  • I'm back in the 80's!
  • PipPipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 15-July 03

Posted 10 October 2004 - 09:35 AM

I coded a map.dat decoder but when I try to reencode it the data ain't the same, I know MSN Messenger doesn't accept the file after it.

the Base64 Encryption is right because I compared it.

Yes I do know there are 2 chars infront off it normal

Code I have for recrypting it
(strData is direct decoded message returned with the getMapdat which works)
Public Function CreateMapDat(strPassport As String, strData As String)
    Dim bytPassword() As Byte
    Dim bytdatin() As Byte
    Dim bytdatout() As Byte
    Dim udtdatout As DATA_BLOB
    Dim udtdatin As DATA_BLOB
    Dim udtPw As DATA_BLOB
    strData = Base64encode(StrConv(strData, vbUnicode)) & "AAA=" & vbNullChar
    sPassword = LCase$(strPassport)
    sData = StrConv(strData, vbFromUnicode)
    bytPassword = StrConv(sPassword, vbUnicode)
    udtPw.cbData = UBound(bytPassword) + 1
    udtPw.pbData = VarPtr(bytPassword(0))
    bytdatin = StrConv(strData, vbUnicode
    udtdatin.cbData = UBound(bytdatin) + 1
    udtdatin.pbData = VarPtr(bytdatin(0))
    Call CryptProtectData(udtdatin, vbNullString, udtPw, ByVal vbNullString, ByVal vbNullString, 0, udtdatout)
    ReDim bytdatout(udtdatout.cbData) As Byte
    Call CopyMemory(bytdatout(0), ByVal udtdatout.pbData, udtdatout.cbData)
    If Dir("C:\TempFile.net") <> "" Then Kill "C:\TempFile.net"
    Open "C:\TempFile.net" For Binary As #1
        Put #1, , bytdatout
    Close #1
End Function

0

#2 User is offline   Daniel

  • Liveā„¢ n00b
  • Icon
  • Group: Admins
  • Posts: 4,598
  • Joined: 01-February 02
  • Location:New Zealand

Posted 10 October 2004 - 11:07 AM

I couldn't get my head around your code, it's been a while since I've totally messed with this, so I'll just post what I made in my custom content manager DLL.

The input sData msnobj shouldn't have the null bytes as this adds them.

Public Function StdEncrypt(ByRef r_sData As String, ByRef r_sPassword As String) As String
    
    Dim abytFileData()  As Byte
    Dim abytPassword()  As Byte
    Dim abytDataOut()   As Byte
    Dim udtDataOut      As DATA_BLOBType
    Dim udtDataIn       As DATA_BLOBType
    Dim udtPw           As DATA_BLOBType
    Dim sData           As String

    sData = StrConv(r_sData & vbNullChar & vbNullChar, vbUnicode)
    sData = Base64EncodeUnicode(sData) & vbNullChar & vbNullChar
    
    'If isNTKernel Then
        abytPassword = StrConv(r_sPassword, vbFromUnicode)
        udtPw.lDataLen = UBound(abytPassword) + 1
        udtPw.lData = VarPtr(abytPassword(0))
        
        abytFileData = StrConv(sData, vbFromUnicode)
        udtDataIn.lDataLen = UBound(abytFileData) + 1
        udtDataIn.lData = VarPtr(abytFileData(0))
        
        Call CryptProtectData(udtDataIn, vbNullString, udtPw, ByVal vbNullString, ByVal vbNullString, 0, udtDataOut)
        ReDim abytDataOut(udtDataOut.lDataLen)
        Call CopyMemory(abytDataOut(0), ByVal udtDataOut.lData, udtDataOut.lDataLen)
        StdEncrypt = Chr$(3) & Chr$(4) & StrConv(abytDataOut, vbUnicode)
         
    'Else
     '   StdEncrypt = sData
    'End If

End Function


Public Declare Function CryptProtectData Lib "crypt32.dll" (ByRef r_udtDataIn As DATA_BLOBType, ByVal v_sDataDescr As String, ByRef r_udtOptionalEntropy As DATA_BLOBType, ByRef r_sReserved As String, ByRef r_sPromptStruct As String, ByVal v_lFlags As Long, ByRef r_udtDataOut As DATA_BLOBType) As Long

Private Type DATA_BLOBType
   lDataLen As Long
   lData As Long
End Type


So, just write to the file what StdEncrypt returns, there's an additional null byte in there somewhere but it doesn't seem to affect it, it still works fine for me.
0

#3 User is offline   The_Huuf

  • I'm back in the 80's!
  • PipPipPipPip
  • Group: Members
  • Posts: 81
  • Joined: 15-July 03

Posted 10 October 2004 - 11:55 AM

After trying several things this didn't work, but i'll try it myself later on

[edit]
I tryd this the udtdataout is correct what goes out off the CryptUnprotectData
the udtdataout is incorrect what goes out off the cryptproductdata

   Call CryptUnprotectData(udtDataIn, vbNullString, udtPw, ByVal vbNullString, ByVal vbNullString, 0, udtDataOut)
    ReDim abytDataOut(udtDataOut.cbData) As Byte
    Call CopyMemory(abytDataOut(0), ByVal udtDataOut.pbData, udtDataOut.cbData)
    udtDataIn = udtDataOut
    Call CryptProtectData(udtDataIn, vbNullString, udtPw, ByVal vbNullString, ByVal vbNullString, 0, udtDataOut)
    ReDim abytDataOut(udtDataOut.cbData)
    Call CopyMemory(abytDataOut(0), ByVal udtDataOut.pbData, udtDataOut.cbData)


[/edit]

This post has been edited by The_Huuf: 10 October 2004 - 01:36 PM

0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users