Quick.Base64.pas 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. { ***************************************************************************
  2. Copyright (c) 2016-2017 Kike Pérez
  3. Unit : Quick.Base64
  4. Description : Base64 functions
  5. Author : Kike Pérez
  6. Version : 1.1
  7. Created : 08/11/2017
  8. Modified : 14/08/2018
  9. This file is part of QuickLib: https://github.com/exilon/QuickLib
  10. ***************************************************************************
  11. Licensed under the Apache License, Version 2.0 (the "License");
  12. you may not use this file except in compliance with the License.
  13. You may obtain a copy of the License at
  14. http://www.apache.org/licenses/LICENSE-2.0
  15. Unless required by applicable law or agreed to in writing, software
  16. distributed under the License is distributed on an "AS IS" BASIS,
  17. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. See the License for the specific language governing permissions and
  19. limitations under the License.
  20. *************************************************************************** }
  21. unit Quick.Base64;
  22. {$i QuickLib.inc}
  23. interface
  24. uses
  25. System.SysUtils,
  26. {$IFDEF DELPHIXE7_UP}
  27. System.NetEncoding;
  28. {$ELSE}
  29. IdCoderMIME,
  30. IdGlobal;
  31. {$ENDIF}
  32. function Base64Encode(const Input: string): string;
  33. function Base64Decode(const Input: string): string;
  34. {$IFDEF DELPHIXE7_UP}
  35. function Base64DecodeFromBinary(const Input: string) : string;
  36. function Base64DecodeToBytes(const Input: string) : TBytes;
  37. {$ENDIF}
  38. implementation
  39. function Base64Encode(const Input: string): string;
  40. begin
  41. {$IFDEF DELPHIXE7_UP}
  42. Result := TNetEncoding.Base64.Encode(Input);
  43. {$ELSE}
  44. Result := TIdEncoderMIME.EncodeString(Input,IndyTextEncoding_OSDefault);
  45. {$ENDIF}
  46. end;
  47. function Base64Decode(const Input: string): string;
  48. begin
  49. {$IFDEF DELPHIXE7_UP}
  50. Result := TNetEncoding.Base64.Decode(Input);
  51. {$ELSE}
  52. Result := TIdDecoderMIME.DecodeString(Input,IndyTextEncoding_OSDefault);
  53. {$ENDIF}
  54. end;
  55. {$IFDEF DELPHIXE7_UP}
  56. function Base64DecodeFromBinary(const Input: string) : string;
  57. var
  58. b : TBytes;
  59. begin
  60. b := TNetEncoding.Base64.DecodeStringToBytes(Input);
  61. Result := TEncoding.ANSI.GetString(b);
  62. end;
  63. function Base64DecodeToBytes(const Input: string) : TBytes;
  64. begin
  65. Result := TNetEncoding.Base64.DecodeStringToBytes(Input);
  66. end;
  67. {$ENDIF}
  68. end.