Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Base64 encoding (https://www.delphipraxis.net/88691-base64-encoding.html)

Remko 19. Mär 2007 14:35


Base64 encoding
 
I'm trying to translate some code from .net (I have it both in c# and VB.net) to Delphi Win32.
The code uses Convert.ToBase64String Method . According to MSDN: Converts an array of 8-bit unsigned integers to its equivalent String representation encoded with base 64 digits.

Is there a WIN32 equivalent?

DGL-luke 19. Mär 2007 14:38

Re: Base64 encoding
 
Hello,


the Base64 format is well documented. http://de.wikipedia.org/wiki/Base64 could be your first source of information.

ste_ett 19. Mär 2007 15:01

Re: Base64 encoding
 
Zitat:

Zitat von Remko
I'm trying to translate some code from .net (I have it both in c# and VB.net) to Delphi Win32.
The code uses Convert.ToBase64String Method . According to MSDN: Converts an array of 8-bit unsigned integers to its equivalent String representation encoded with base 64 digits.

Is there a WIN32 equivalent?

8 bit unsigned integer is a normal Byte.
Delphi-Quellcode:
var
  data: array of Byte;

Remko 19. Mär 2007 15:04

Re: Base64 encoding
 
What is the output, hex bytes or Base64 string?

DGL-luke 19. Mär 2007 15:05

Re: Base64 encoding
 
ToBase64 would be the readable form, i.e. the Base64 string.

Remko 19. Mär 2007 15:18

Re: Base64 encoding
 
I'm a little confused. I should tell more about the purpose.
I want to create an .RDP file programmatically, with this file it's possible to start a Remote Desktop (Terminal) session.
An RDP file contains an encrypted password which is encrypted with the MSDN-Library durchsuchenCryptProtectData API (this part I got working).
However it also seems to be Base64 encoded, I found this here:

http://bbs.vbstreets.ru/viewtopic.ph...2838b771a1fc69 (translated: http://www.google.com/translate?u=ht...&hl=en&ie=UTF8)

and here:
http://www.anappaday.com/downloads/2...p-manager.html

Edit: I forgot to mention: the resulting hashed password is a fixed size (always 1329) hex bytes like this:
password 51:b:01000000D08C9DDF0115D1118C7A00C04FC297EB01000 00062BB0C5189FAB446A21158EC44C474F5 (removed the rest).

marabu 19. Mär 2007 17:21

Re: Base64 encoding
 
Hi Remko,

there is a function CryptStringToBinary() coming with the Crypto API (crypt32.dll, wincrypt.h), that could be of some value.

Regards

Remko 19. Mär 2007 17:45

Re: Base64 encoding
 
Thanks, I'm going to look at. Meanwhile some progress:
I can now successfully create a .rdp file and logon with even though the hashed password I create is not the same size as the one that MS makes. The hashed password remains valid during the logon session of the logged on user (the user under who's account the password was hashed). Although this achieves the goal I had in mind, I'm curious as to how MS (mstsc.exe) does it.

Debugging MSTSC.EXE while saving an RDP shows this sequence:

CryptProtectData - CRYPT32.dll
CryptUnprotectData - CRYPT32.dll
CryptUnprotectData - CRYPT32.dll
CryptProtectData - CRYPT32.dll

It seems like the first CryptProtectData crypts the username (I passed Username as user)
http://web.inter.nl.net/users/weijnen/dp/Info1.jpg
And the 2nd CryptProtectData the Password (I passed Password as the password string)
http://web.inter.nl.net/users/weijnen/dp/Info2.jpg

Perhaps the 2 sequences are appended? Don't know why and where the Base64 comes in (yet).

Remko 20. Mär 2007 08:44

Re: Base64 encoding
 
Well it seems that in the sample code I found the Base64 is only used to display the encoded binary as hex string.
I made a new topic with the right topic title Password hash in RDP files


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz