Visualizzazione dei risultati da 1 a 9 su 9
  1. #1

    Vb6 - Codificare e Decodificare dati in base64

    Come posso codificare e decodificare dati in base64?

    Ad es per codificare un allegato di posta in base64
    :sexpulp: V3g4 :sexpulp:

  2. #2
    Se ho capito bene vuoi portare la keyascii dei caratteri che è in base 10 a base 64 giusto?
    "Penso che nel mondo ci sia mercato per quattro o cinque computer"... Thomas Watson, presidente della IBM, 1943

  3. #3
    una cosa simile...
    :sexpulp: V3g4 :sexpulp:

  4. #4
    Guarda ti posso dire che per convertire un numero decimale ad una qualsiasi base puoi usare il metodo delle divisioni.

    tu prendi il tuo numero in base 10 e lo dividi per 64 che è la tua base

    ricordandoti di segnare tutti i resti.

    mettiamo che i resti siano 1 5 6

    Ecco i resti presi al contrario formano il tuo numero in base 64.

    Incomincia però a diventare un po scomodo se i resti sono da due cifre.

    Ti conviene utilizzare per la tua base altri simboli...

    ciao ciao
    "Penso che nel mondo ci sia mercato per quattro o cinque computer"... Thomas Watson, presidente della IBM, 1943

  5. #5

    non intendevo quel base64 allora...

    il mio problema è preparare un file in base64 per inviarlo come allegato in una mail. Non so se ci sia qualcosa per far ciò.. però mi posso inventare qualcosina.. :master:
    grazie cmq
    :sexpulp: V3g4 :sexpulp:

  6. #6
    Utente bannato
    Registrato dal
    Sep 2003
    Messaggi
    1,012
    Cos'è un file in base64?

  7. #7
    Se mi dici in base 64 l'unica cosa che si può intendere e portare la keyascii da 10 a 64...

    Nn so... dimmi cosa vuoi fare...
    "Penso che nel mondo ci sia mercato per quattro o cinque computer"... Thomas Watson, presidente della IBM, 1943

  8. #8
    Hai mai aperto le proprietà di una e-mail?

    All'interno l'allegato è stato codificato con base64
    Si nota anche da un tag che lo precede, in cui viene indicato che il file contenuto è stato crittografato in base64.

    a me interesserebbe riuscire a riprodurre quel tipo di codifica

    meglio ora ?
    :sexpulp: V3g4 :sexpulp:

  9. #9
    codice:
    ' Decodes a base-64 encoded string (BSTR type).
    ' 1999 - 2004 Antonin Foller, http://www.pstruh.cz
    ' 1.01 - solves problem with Access And 'Compare Database' (InStr)
    Function Base64Decode(ByVal base64String)
      'rfc1521
      '1999 Antonin Foller, PSTRUH Software, http://pstruh.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
    codice:
    Function Base64Encode(inData)
      'rfc1521
      '2001 Antonin Foller, PSTRUH Software, http://pstruh.cz
      Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim cOut, sOut, I
      
      'For each group of 3 bytes
      For I = 1 To Len(inData) Step 3
        Dim nGroup, pOut, sGroup
        
        'Create one long from this 3 bytes.
        nGroup = &H10000 * Asc(Mid(inData, I, 1)) + _
          &H100 * MyASC(Mid(inData, I + 1, 1)) + MyASC(Mid(inData, I + 2, 1))
        
        'Oct splits the long To 8 groups with 3 bits
        nGroup = Oct(nGroup)
        
        'Add leading zeros
        nGroup = String(8 - Len(nGroup), "0") & nGroup
        
        'Convert To base64
        pOut = Mid(Base64, CLng("&o" & Mid(nGroup, 1, 2)) + 1, 1) + _
          Mid(Base64, CLng("&o" & Mid(nGroup, 3, 2)) + 1, 1) + _
          Mid(Base64, CLng("&o" & Mid(nGroup, 5, 2)) + 1, 1) + _
          Mid(Base64, CLng("&o" & Mid(nGroup, 7, 2)) + 1, 1)
        
        'Add the part To OutPut string
        sOut = sOut + pOut
        
        'Add a new line For Each 76 chars In dest (76*3/4 = 57)
        'If (I + 2) Mod 57 = 0 Then sOut = sOut + vbCrLf
      Next
      Select Case Len(inData) Mod 3
        Case 1: '8 bit final
          sOut = Left(sOut, Len(sOut) - 2) + "=="
        Case 2: '16 bit final
          sOut = Left(sOut, Len(sOut) - 1) + "="
      End Select
      Base64Encode = sOut
    End Function
    
    Function MyASC(OneChar)
      If OneChar = "" Then MyASC = 0 Else MyASC = Asc(OneChar)
    End Function
    le ho trovate su google

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.