Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How am I supposed to use Blowfish ? #35

Open
TegFu opened this issue Oct 14, 2024 · 2 comments
Open

How am I supposed to use Blowfish ? #35

TegFu opened this issue Oct 14, 2024 · 2 comments

Comments

@TegFu
Copy link

TegFu commented Oct 14, 2024

Looking at the code in uTPLb_BlowFish, I need to use TBlowFish.GenerateKey, to then be able to use the generated data in Blowfish_Encrypt ? But everything is private so I don't know how I'm supposed to actually use it ?

@TegFu
Copy link
Author

TegFu commented Oct 14, 2024

Okay I managed to figure out some things by straight-up reading the code.

  Codec := TCodec.Create(nil);
  Codec.CryptoLibrary := TCryptographicLibrary.Create(nil);
  Codec.StreamCipherId := BlockCipher_ProgId;
  Codec.BlockCipherId := Blowfish_ProgId;
  Codec.ChainModeId := CBC_ProgId;
  SetLength(LBKeyBytes, 34);
  Move(keyBytes[0], LBKeyBytes[1], 32); // keyBytes = SHA1('pass') + MD5('pass')
  LBKeyBytes[0] := 32; // Length of the key
  LBKeyBytes[33] := 0; // Does the key contain the stores
  setIV := TIVZero.Create();
  Codec.OnSetIV := setIV.SetIV;
  Codec.InitFromStream(TBytesStream.Create(LBKeyBytes));
  Codec.EncryptString('ABCDEFGH', outputText, TEncoding.UTF8);

I'm still missing the option to disregard padding (ie encrypting 'AB' here should lead to an output of 0xE214 ; for now I'm getting 0xE22F and it changes as I add characters up until I get to 8, at which point it becomes correct : 0x92D48AB3B9F991FA).

Thanks :)

@TegFu
Copy link
Author

TegFu commented Oct 18, 2024

Other question : I noticed that encoding the same thing 3 times gives a different output, despite me creating a new TCodec and a new TCryptographyLibrary everytime. What gives ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant