Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11

Discussione: Codifica con base64

  1. #1

    Codifica con base64

    Ciao a tutti
    ho un problema devo codificare una stringa criptata in md5 con base64.
    sono disperato ho cercato un po ovunque ma trovo solo delle applicazioni da installare sul server cosa che non posso fare perchè non ho un server mio.
    Qualcuno ha qualche idea???


    questo e un codice di esempio che ho recuperato ma non capisco perche non converta...
    il risultato di sOut e nullo


    <%
    inData = "testo_da_convertire"
    Function Base64Encode(inData)
    'rfc1521
    '2001 Antonin Foller, Motobit Software, http://Motobit.cz
    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"
    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
    response.Write(sOut)
    response.Write(inData)
    %>

  2. #2

  3. #3

    RISOLTO

    RISOLTO

  4. #4

    Re: Codifica con base64

    Originariamente inviato da Fesc_098sl
    Ciao a tutti
    ho un problema devo codificare una stringa criptata in md5 con base64.
    sono disperato ho cercato un po ovunque ma trovo solo delle applicazioni da installare sul server cosa che non posso fare perchè non ho un server mio.
    Qualcuno ha qualche idea???


    questo e un codice di esempio che ho recuperato ma non capisco perche non converta...
    il risultato di sOut e nullo


    <%
    inData = "testo_da_convertire"
    Function Base64Encode(inData)
    'rfc1521
    '2001 Antonin Foller, Motobit Software, http://Motobit.cz
    Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"
    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
    response.Write(sOut)
    response.Write(inData)
    %>

  5. #5
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881

    help

    sto usando uno script dello stesso autore per decodificare una stringa in base64 ma non capisco in cosa me la converta!!!
    Lo script è il seguente:

    ' 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 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw xyz0123456789+/"
    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
    che dovrebbe tradurmi la stringa che gli passo in una immagine.

    Per provare a visualizzare quella l'immagine ho scritto
    response.write(Base64Decode(stringa))
    ma il risultato a video in FF è questo

    �PNG 

    ????
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  6. #6
    ma la stringa sarebbe una png codificata?
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  7. #7
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881
    si, dovrebbe essere un png
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  8. #8
    codice:
    response.contentType = "image/png"
    response.write(Base64Decode(stringa))
    ma devono essere gli unici due response della pagina
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  9. #9
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881
    mah mi dice che l'immagine non può essere visualizzata perchè contiene degli errori
    probabilmente la stringa che gli passo è inesatta/incompleta.... verificherò.

    grazie
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

  10. #10
    Utente di HTML.it L'avatar di supermac
    Registrato dal
    Jun 2001
    Messaggi
    1,881
    immagino che il contentype non pòssa essere ridefinito più volte nella stessa pagina, giusto?
    se fosse potrei visualizzare il mio png ed eventuale altro codice in base 64 tradotto...
    W la Ferari effetrenavenave!
    il computer è un somaro veloce! (neanche tanto ndr)

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 © 2026 vBulletin Solutions, Inc. All rights reserved.