Seite 1 von 1

AES Verschlüsselte Datei speichern

Verfasst: 25.10.2009 23:51
von haggi
Hallo Leute,

ich beziehe mich hier auf den folgenden code ... http://forums.purebasic.com/german/view ... b7#p258716

ich hab dabei folgendes Problem und ich hoffe Ihr könnt mir helfen ... wie kann ich die datn saubr in eine datei speichern und nacher wieder laden und decrypten kann?

danke schon im vorraus

gruß haggi

Re: AES Verschlüsselte Datei speichern

Verfasst: 26.10.2009 01:06
von ts-soft
Ohne das verlinkte Beispiel könnte es so aussehen:

Code: Alles auswählen

Procedure schreibe(*mem, file.s)
  Protected ff
  ff = CreateFile(#PB_Any, file)
  If ff
    WriteData(ff, *mem, MemorySize(*mem))
    CloseFile(ff)
  EndIf
EndProcedure

Procedure.s lese(file.s)
  Protected result.s, ff, *mem1, *mem2, length
  ff = ReadFile(#PB_Any, file)

  If ff
    length = Lof(ff)
    *mem1 = AllocateMemory(length)
    *mem2 = AllocateMemory(length)
    If *mem1 And *mem2
      ReadData(ff, *mem1, length)
      AESDecoder(*mem1, *mem2, length, ?Key, 128, ?InitializationVector)
      result = PeekS(*mem2)
      FreeMemory(*mem1) : FreeMemory(*mem2)
    EndIf
    CloseFile(ff)
  EndIf
  ProcedureReturn result
EndProcedure

String$ = "Hello this is a test for AES"

*CipheredString = AllocateMemory(StringByteLength(String$) + SizeOf(character))

If AESEncoder(@String$, *CipheredString, StringByteLength(String$) + SizeOf(character), ?Key, 128, ?InitializationVector)

  schreibe(*CipheredString, GetTemporaryDirectory() + "test.bin")
  FreeMemory(*CipheredString)
  Debug lese(GetTemporaryDirectory() + "test.bin")
EndIf

DataSection
  Key:
  Data.b $06, $a9, $21, $40, $36, $b8, $a1, $5b, $51, $2e, $03, $d5, $34, $12, $00, $06

  InitializationVector:
  Data.b $3d, $af, $ba, $42, $9d, $9e, $b4, $30, $b4, $22, $da, $80, $2c, $9f, $ac, $41
EndDataSection
Gruß
Thomas

Re: AES Verschlüsselte Datei speichern

Verfasst: 26.10.2009 01:27
von haggi
super!


vielen dank, für die schnelle Antwort!!!


danach hab ich gesucht!


gruß haggi