Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Desarrollo en Delphi para Android (https://www.clubdelphi.com/foros/forumdisplay.php?f=57)
-   -   Funcion encriptar/desencriptar texto android (https://www.clubdelphi.com/foros/showthread.php?t=90578)

look 14-07-2016 19:15:38

Funcion encriptar/desencriptar texto android
 
Encontre esta simple funcion para encriptar texto, me gustaria pasarla a android.
espero me ayuden, oh si alguien sabe como cifrar y descifrar texto en android...
Saludos!
Código Delphi [-]
    const CKEY1 = 53761;
          CKEY2 = 32618;
     
    function EncryptStr(const S :WideString; Key: Word): String;
    var   i          :Integer;
          RStr       :RawByteString;
          RStrB      :TBytes Absolute RStr;
    begin
      Result:= '';
      RStr:= UTF8Encode(S);
      for i := 0 to Length(RStr)-1 do begin
        RStrB[i] := RStrB[i] xor (Key shr 8);
        Key := (RStrB[i] + Key) * CKEY1 + CKEY2;
      end;
      for i := 0 to Length(RStr)-1 do begin
        Result:= Result + IntToHex(RStrB[i], 2);
      end;
    end;
     
    function DecryptStr(const S: String; Key: Word): String;
    var   i, tmpKey  :Integer;
          RStr       :RawByteString;
          RStrB      :TBytes Absolute RStr;
          tmpStr     :string;
    begin
      tmpStr:= UpperCase(S);
      SetLength(RStr, Length(tmpStr) div 2);
      i:= 1;
      try
        while (i < Length(tmpStr)) do begin
          RStrB[i div 2]:= StrToInt('$' + tmpStr[i] + tmpStr[i+1]);
          Inc(i, 2);
        end;
      except
        Result:= '';
        Exit;
      end;
      for i := 0 to Length(RStr)-1 do begin
        tmpKey:= RStrB[i];
        RStrB[i] := RStrB[i] xor (Key shr 8);
        Key := (tmpKey + Key) * CKEY1 + CKEY2;
      end;
      Result:= UTF8Decode(RStr);
    end;

mamcx 15-07-2016 01:39:24

Eso no es codigo correcto para encriptar.

Debes usar una libreria de encriptacion hecha por PROFESIONALES. Nunca te inventes eso ni copies a ciegas lo que sale en internet.

Para que sepas, busca una libreria que haga Bcrypt, Scrypt o PBKDF2 (mejor).


La franja horaria es GMT +2. Ahora son las 18:35:28.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi