C# save file
Hi, I have a function that encrypt some string and i want to encrypt an image with it, but when i decrypt it it is just bricked; this is my code; feel free to mp me if you need more info
53 Replies
what does EncryptText ?
images cannot be read or written as text
they're binary data, attempting to treat them as text will always corrupt it
and yeah, how do EncryptText and DecryptText work?
also, use $code for sharing snippets
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/wait
look what modix said
not encrypted:
encrypted and decrypted
some characters are borkens
first stop try to writing image as text
that cannot work
i tried to encrypt bites and things like that but i didnt succeeds
bytes *
how do i do then
use base64
also dont work with base64
original and encrypted and decrypted with base64
Has to work with Base64
Or you're doing something else wrong
Code for reference:
ty i'll try tomorrow
bc its getting a little late in France
unless it has changed, you're reading the file content into a string, so that borks it from the start
you'll need to read it into a byte array or similar
oh ok
but how do i encrypt it then
ok but i dont want to encrypt it with b64 it is not secure
i have this for encryption
how can i use this
give as input your base64 string
btw microsoft doc has an easier way to do AES encryption
i do but it dont work
so you've done something wrong
what's the issue ?
look the bad thingsd that i made
my encrypt thing
and decrypt
i tried to do some bytes to things things
but it fail in the decrypt function
cause you don't decode your base64
you write directly the base64 into a file
there is a method in Convert to get bytes from a base64
what is the method ?
this is the error
i says that there is non-base64 characters @xtreit
You have to use it when you write the file
1. Read bytes
2. Convert to base64
3. Encrypt the base64 string
4. Save
To load,
1. Load
2. Get the enctrypted string
3. Decrypt it
4. Base64-decode it back into bytes
5. Save the bytes as a file
do i need to reconvert it to bytes when i save it?
it say it cant convert from byte to char
Are you trying to use
File.WriteAllText()
or something?And where do you get this error?
wait
i fixed it but wait
this is the decrypted and the original
this is all my code: