Posty bez odpowiedzi |oraz Aktywne tematy Dzisiaj jest 2024-03-28, 18:12x



Odpowiedz w temacie  [ Posty: 9 ] 
Dekodowanie base64 
Autor Wiadomość

Rejestracja: 2015-12-03, 16:37
Posty: 18
Post Dekodowanie base64
Cześć
Muszę zdekodować ciąg znaków base64. W jaki sposób można to zrobić w raporcie w Handlu?

Myślałem, żeby użyć metody System.Convert, ale nie potrafię jej zaimplementować. Jeżeli zrobię
Kod:
dispatch sys = "System.Convert"

to dostaję komunikat
Cytuj:
Nie można utworzyć obiektu: System.Convert

Tak samo jest z
Kod:
dispatch sys = "System"


W jaki sposób mogę uruchomić System.Convert?


2017-07-28, 12:52
Wyświetl profil
Autor Wiadomość
 


Ekspert
Ekspert

Rejestracja: 2007-11-16, 15:08
Posty: 3982
Pomógł: 445
Post Re: Dekodowanie base64
Ta wiadomość była pomocna.(1)
za pomocą VBScript

Kod:
' Decodes a base-64 encoded string (BSTR type).
' 1999 - 2004 Antonin Foller, http://www.motobit.com
' 1.01 - solves problem with Access And 'Compare Database' (InStr)
Function Base64Decode(ByVal base64String)
  'rfc1521
  '1999 Antonin Foller, Motobit Software, http://Motobit.cz
  Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  Dim dataLength, sOut, groupBegin
 
  'remove white spaces, If any
  base64String = Replace(base64String, vbCrLf, "")
  base64String = Replace(base64String, vbTab, "")
  base64String = Replace(base64String, " ", "")
 
  'The source must consists from groups with Len of 4 chars
  dataLength = Len(base64String)
  If dataLength Mod 4 <> 0 Then
    Err.Raise 1, "Base64Decode", "Bad Base64 string."
    Exit Function
  End If

 
  ' Now decode each group:
  For groupBegin = 1 To dataLength Step 4
    Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
    ' Each data group encodes up To 3 actual bytes.
    numDataBytes = 3
    nGroup = 0

    For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)

      thisChar = Mid(base64String, groupBegin + CharCounter, 1)

      If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If

      nGroup = 64 * nGroup + thisData
    Next
   
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
   
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
   
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
   
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
  Next

  Base64Decode = sOut
End Function

_________________
Skontaktuj się z Ekspertem | Zamów dodatek

tel. 22 7 538 538
ekspert@mojaSymfonia.pl
http://www.mojaSymfonia.pl


2017-07-28, 20:09
Wyświetl profil

Rejestracja: 2015-12-03, 16:37
Posty: 18
Post Re: Dekodowanie base64
Potrzebuję użyć tego w Symfonii Premium, więc VBScript raczej odpada?
Jest jakiś inny sposób?


2017-07-31, 08:33
Wyświetl profil
Ekspert
Ekspert

Rejestracja: 2007-11-16, 15:08
Posty: 3982
Pomógł: 445
Post Re: Dekodowanie base64
Ta wiadomość była pomocna.(1)
Mylisz się.

Przykład użycia VBScript w Symfonii viewtopic.php?p=32728#p32728

_________________
Skontaktuj się z Ekspertem | Zamów dodatek

tel. 22 7 538 538
ekspert@mojaSymfonia.pl
http://www.mojaSymfonia.pl


2017-07-31, 10:10
Wyświetl profil

Rejestracja: 2015-12-03, 16:37
Posty: 18
Post Re: Dekodowanie base64
Super sprawa, dzięki :)
Ale mam kolejny problem. Do tego skryptu przekazuję zawartość zakodowanego pliku pdf - około 68 000 znaków. Jako wynik powinienem otrzymać około 50000 znaków, które po umieszczeniu w pliku o rozszerzeniu pdf powinny dać się otworzyć jako pdf.
Dostaję tylko to:
Cytuj:
%PDF-1.3
%âăĎÓ
20 0 obj
<<
/Linearized 1
/O 23
/H [ 813 249 ]
/L 51497
/E 46064
/N 4
/T 50979
>>
endobj
xref
20 17
0000000016 00000 n
0000000687 00000 n
0000000774 00000 n
0000001062 00000 n
0000001216 00000 n
0000001449 00000 n
0000001554 00000 n
0000001660 00000 n
0000001709 00000 n
0000003024 00000 n
0000003204 00000 n
0000004061 00000 n
0000035850 00000 n
0000044458 00000 n
0000045777 00000 n
0000000813 00000 n
0000001041 00000 n
trailer
<<
/Size 37
/Info 18 0 R
/Root 21 0 R
/Prev 50969
/ID[<20c962f98d87f8beaa93fa3d8426d8b6><20c962f98d87f8beaa93fa3d8426d8b6>]
>>
startxref
0
%%EOF

21 0 obj
<<
/Type /Catalog
/Pages 19 0 R
/Names 22 0 R
/Outlines 8 0 R
>>
endobj
22 0 obj
<<
/Dests 17 0 R
>>
endobj
35 0 obj
<< /S 72 /O 125 /E 141 /Filter /FlateDecode /Length 36 0 R >>
stream
H‰b```d``Öe`a``¸Č Ŕ€


Czy coś robię źle?


2017-07-31, 14:19
Wyświetl profil
Ekspert
Ekspert

Rejestracja: 2007-11-16, 15:08
Posty: 3982
Pomógł: 445
Post Re: Dekodowanie base64
Uzyj polecenia

Kod:
limit 80000

_________________
Skontaktuj się z Ekspertem | Zamów dodatek

tel. 22 7 538 538
ekspert@mojaSymfonia.pl
http://www.mojaSymfonia.pl


2017-07-31, 16:42
Wyświetl profil

Rejestracja: 2015-12-03, 16:37
Posty: 18
Post Re: Dekodowanie base64
Próbowałem, to niestety nie rozwiązuje problemu. Większe wartości w poleceniu Limit też nie
Chciałbym jeszcze żeby działało to jako funkcja - żeby można było wykorzystać to np w pętli. Da się tak z zasobami?

Cały kod:
Kod:
limit 80000

string sScript, sCzytaj
int iLinia
 
Zasoby(Ustaw,iLinia +=1)
while Zasoby(Czytaj, sCzytaj)
   sScript += sCzytaj
   Zasoby(Ustaw,iLinia +=1)
wend

dispatch sc  = "MSScriptControl.ScriptControl"
sc.Language = "VBScript"
sc.AddCode( sScript )
dispatch fso = "Scripting.FileSystemObject"

dispatch tmpFile
   string tmp = KatalogFirmy() + "labelrecet.tmp"
   tmpFile = fso.OpenTextFile( tmp, 1 )
   string label = tmpFile.ReadLine
   tmpFile.Close


string labelext = sc.Run("Base64Decode",label)
   string tmpr = KatalogFirmy() + "labelrecetr.tmp"
   fso.CreateTextFile( tmpr, 1 )
   tmpFile = fso.OpenTextFile( tmpr, 2 )
   tmpFile.WriteLine( labelext )
   tmpFile.Close

   
zasoby:
'VB Script
' Decodes a base-64 encoded string (BSTR type).
' 1999 - 2004 Antonin Foller, http://www.motobit.com
' 1.01 - solves problem with Access And 'Compare Database' (InStr)
Function Base64Decode(ByVal base64String)
  'rfc1521
  '1999 Antonin Foller, Motobit Software, http://Motobit.cz
  Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  Dim dataLength, sOut, groupBegin

  'remove white spaces, If any
  base64String = Replace(base64String, vbCrLf, "")
  base64String = Replace(base64String, vbTab, "")
  base64String = Replace(base64String, " ", "")

  'The source must consists from groups with Len of 4 chars
  dataLength = Len(base64String)
  If dataLength Mod 4 <> 0 Then
    Err.Raise 1, "Base64Decode", "Bad Base64 string."
    Exit Function
  End If


  ' Now decode each group:
  For groupBegin = 1 To dataLength Step 4
    Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
    ' Each data group encodes up To 3 actual bytes.
    numDataBytes = 3
    nGroup = 0

    For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)

      thisChar = Mid(base64String, groupBegin + CharCounter, 1)

      If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If

      nGroup = 64 * nGroup + thisData
    Next
   
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
   
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
   
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
   
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
  Next

  Base64Decode = sOut
End Function



2017-07-31, 21:16
Wyświetl profil
Ekspert
Ekspert

Rejestracja: 2007-11-16, 15:08
Posty: 3982
Pomógł: 445
Post Re: Dekodowanie base64
Ta wiadomość była pomocna.(1)
To zapisuj do pliku w VBScript a nie w AmBasic

_________________
Skontaktuj się z Ekspertem | Zamów dodatek

tel. 22 7 538 538
ekspert@mojaSymfonia.pl
http://www.mojaSymfonia.pl


2017-08-01, 08:18
Wyświetl profil

Rejestracja: 2015-12-03, 16:37
Posty: 18
Post Re: Dekodowanie base64
Super, dzięki :)


2017-08-01, 11:28
Wyświetl profil
Wyświetl posty nie starsze niż:  Sortuj wg  
Odpowiedz w temacie   [ Posty: 9 ] 

Kto jest online

Użytkownicy przeglądający to forum: Nie ma żadnego zarejestrowanego użytkownika i 23 gości


Nie możesz tworzyć nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz dodawać załączników

Szukaj:
Przejdź do:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Support forum phpbb by phpBB Assistant