| Autor |
Beitrag |
m-s
      
Beiträge: 149
Erhaltene Danke: 7
Win 10
C# (VS 2015)
|
Verfasst: So 19.06.11 12:27
Hallo Zusammen,
ich habe schon mit dem einen oder anderen Programmierer zusammen versucht eine Lösung zu finden, aber bisher sind wir immer noch ein Stück entfernt.
Vielleicht kennt sich ja einer von Euch aus und findet einen Weg.
Warum geht's?
Es gibt eine Software (Datenbank) die unter WebOS läuft in der man verschlüsselte Daten speichern kann. Diese Daten würde ich gerne am PC lesen/schreiben können. WebOS bietet eine Verschlüsslung auf BlowFisch Basis an. Leider scheint die nicht so ganz richtig kommentiert zu sein so das es uns bisher nicht gelungen ist auf die gleichen Ergebnisse zu kommen bzw. auf dem WebOS verschlüsselte Daten auf dem PC zu entschlüsseln oder umgekehrt.
Was gibt's schon?
Wir haben alles mögliche versucht und der letzte Stand ist in einem einfachen Projekt.
Das Projekt hat nur eine Form in der die Buttons für die Ver- und Entschlüsslung sind.
Der derzeitige Knackpunkt ist wohl, dass im WebOS eine Blibliothek verwendet wird deren Quelltext ich nicht finden kann. Darin wird wohl zuerst der Schlüssel in Base64 codiert und dann für die Verschlüsslung verwendet. Anscheinend macht unser Quelltext was anders, weswegen wir dann auch auf andere Ergebnisse kommen.
In einem Palm Forum habe ich schon mal nen paar Infos geschrieben bisher wusste da aber keiner Rat.
Dann gibt es noch zwei Interessante Beiträge in einem anderen Forum, hier mal rein kopiert
| Zitat: | ________
Here's a description of the blowfish implementation used:
'We use blowfish 64-bit block cipher. The input string is treated as UTF-8 bytes which become the "key." The output from the encrypter (which is binary) is base64 encoded, and returned to JavaScript as a string. Decrypt takes the base64'ed string, converts it to the binary stream, and runs the blowfish 64-bit block decoder on it. It is assumed the same key "string" is used in both cases.'
Let me know if more is needed.
______________
Just a few brief words of follow up on this topic for those interested in using these interfaces.
First, we are aware of the limitations of this interface and desire for support for additional ciphers, hashes, etc. While as usual we can't comment on support timeframe we do recognize the importance of this functionality to developers.
Second, there is an important detail to note about the current Blowfish implementation per the above explanation. All invocations use the same "zero" IV. This has two implications worth noting.
The most important is that it can cause compatibility issues with external implementations. If your application is attempting to process data encrypted by an external source that used a different IV you will not be able to encrypt/decrypt the data. If you are encrypting data to send to another source you can specify the zero IV and they will be able to decrypt it. However if they send you data with a non-zero IV you will not be able to decrypt it. Also if they expect you to send data encrypted using a non-zero IV you will not be able to do so. This limitation will not have any effect on your ability to use the API locally to encrypt and save your own data.
It is also worth nothing that reusing the same IV is not considered best practice in cryptography. Reusing IVs in Blowfish CFB mode is not a significant cryptanalysis issue if the data being encrypted varies in the first block. However if two plaintexts share identical first blocks, then an attacker who can view the ciphertext can see that they have identical first blocks, but not what the plaintext of those blocks is. Still, that knowledge may help the attacker in some way, depending on the structure of the plaintext. If you have concerns about even this minimal leakage of information, prepending a block of random data to the plaintext to be encrypted will have a similar effect.
--brian
|
Unser Quelltext sieht so aus:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace BlowFischTest { public partial class Form1 : Form { string tschluessel;
public Form1() { InitializeComponent(); tschluessel = "Toller Key";
textBox_original.Text = "LaberLaber"; }
private void btn_verschluesseln_Click(object sender, EventArgs e) { System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
byte[] key = enc.GetBytes(tschluessel); byte[] data = enc.GetBytes(textBox_original.Text); byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] ret;
using (OpenSSL.Crypto.CipherContext cc = new OpenSSL.Crypto.CipherContext(OpenSSL.Crypto.Cipher.Blowfish_CFB64)) { ret = cc.Encrypt(data, key, iv, 0); }
textBox_blowfish.Text = Convert.ToBase64String(ret); }
private byte[] StringToByteArray(string str) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetBytes(str); }
private string ByteArrayToString(byte[] arr) { System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); return enc.GetString(arr); }
private void btn_entschluesseln_Click(object sender, EventArgs e) { System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
byte[] key = enc.GetBytes(tschluessel); byte[] data = Convert.FromBase64String(textBox_blowfish.Text); byte[] iv = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; byte[] ret;
using (OpenSSL.Crypto.CipherContext cc = new OpenSSL.Crypto.CipherContext(OpenSSL.Crypto.Cipher.Blowfish_CFB64)) { ret = cc.Decrypt(data, key, iv, 0); }
textBox_original.Text = enc.GetString(ret); }
static public string DecodeFrom64(string encodedData) {
byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
return returnValue; }
static public string EncodeTo64(string toEncode) {
byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
return returnValue;
}
public string base64Encode(string data) { try { byte[] encData_byte = new byte[data.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(data); string encodedData = Convert.ToBase64String(encData_byte); return encodedData; } catch (Exception e) { throw new Exception("Error in base64Encode" + e.Message); } }
public string base64Decode(string data) { try { System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecode_byte = Convert.FromBase64String(data); int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length); char[] decoded_char = new char[charCount]; utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0); string result = new String(decoded_char); return result; } catch (Exception e) { throw new Exception("Error in base64Decode" + e.Message); } }
private void button1_Click(object sender, EventArgs e) { string myData = textBox_original.Text; string myDataEncoded = base64Encode(myData); textBox_blowfish.Text = myDataEncoded; }
private void button2_Click(object sender, EventArgs e) { string myData = textBox_blowfish.Text; string myDataEncoded = base64Decode(myData); textBox_original.Text = myDataEncoded; }
private void Form1_Load(object sender, EventArgs e) {
} } } |
Die OpenSSL Bibliothek mit der wir gearbeitet haben, ist angefügt (zip, 700.58 KB).
Wäre super wenn jemand ne Idee nen Vorschlag oder sonst was tolles weiß.
Einloggen, um Attachments anzusehen!
_________________ Gruß Markus
|
|
Trashkid2000
      
Beiträge: 561
Erhaltene Danke: 137
|
Verfasst: So 19.06.11 13:49
Hallo,
sieht so aus, als ob die ManagedOpenSSl kein BlowFish kennt. Oder ich habe es nur nicht gefunden.
Habe mal was auf PasteBin gefunden, was die nativen Calls der libeay32.dll nutzt:
pastebin.com/2Q83iRZ6
Originaltext: LaberLaber
Key: Toller Key
Verschlüsslung mit WebOS ergibt: nI5jEmjyuIklHQ==
Verschlüsselung mit C# und der genannten Klasse: nI5jEmjyuIklHQ== -> also gleich
Code zum verschlüsseln:
C#-Quelltext 1: 2: 3: 4:
| Blowfish bf = new Blowfish(BlowfishAlgorithm.CFB64); bf.SetKey(Encoding.UTF8.GetBytes("Toller Key")); string crypted = Convert.ToBase64String(bf.Encrypt(Encoding.UTF8.GetBytes("LaberLaber"))); |
//edit: okay, die ManagedOpenSSL kennt doch BlowFish, wie man an Deinem Code sieht. K.A., warum bei der Verwendung nicht das gleiche Ergebnis rauskommt. Habe gedacht, dass es an dem IV-Array liegt (denn an was sonst?). Aber nach durchgehen aller Möglichkeiten der Bytes in dem Array kam auch nie das erwartete Ergebnis raus.
LG
Für diesen Beitrag haben gedankt: m-s
|
|
m-s 
      
Beiträge: 149
Erhaltene Danke: 7
Win 10
C# (VS 2015)
|
Verfasst: Mo 20.06.11 00:20
Hi Marko,
echt super, Habs mal eben eingebaut und nachgestellt und jepp macht genau was es soll.
Echt super. vielen Dank . . .
_________________ Gruß Markus
|
|
Trashkid2000
      
Beiträge: 561
Erhaltene Danke: 137
|
Verfasst: Mo 20.06.11 06:33
Schön, dass es geklappt hat.
Werde mal noch die Klasse von PasteBin hier posten, wenn das okay ist.
Nur, falls die Seite mal nicht mehr verfügbar ist...
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
| using System; using System.Runtime.InteropServices;
namespace OpenSSL.Crypto { public enum BlowfishAlgorithm { ECB, CBC, CFB64, OFB64, };
public class Blowfish : IDisposable { [DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)] public extern static void BF_set_key(IntPtr _key, int len, byte[] data);
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)] public extern static void BF_ecb_encrypt(byte[] in_, byte[] out_, IntPtr schedule, int enc);
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)] public extern static void BF_cbc_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, int enc);
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)] public extern static void BF_cfb64_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, ref int num, int enc);
[DllImport("libeay32.dll", CallingConvention = CallingConvention.Cdecl)] public extern static void BF_ofb64_encrypt(byte[] in_, byte[] out_, int length, IntPtr schedule, byte[] ivec, out int num);
[StructLayout(LayoutKind.Sequential)] struct bf_key_st { [MarshalAs(UnmanagedType.ByValArray, SizeConst = 18)] public UInt32[] P; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1024)] public UInt32[] S; }
private BlowfishAlgorithm _algorithm; private IntPtr _key; private byte[] _encryptIv; private byte[] _decryptIv; private int _encryptNum; private int _decryptNum;
public Blowfish(BlowfishAlgorithm algorithm) { _algorithm = algorithm; _encryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 }; _decryptIv = new byte[8] { 0, 0, 0, 0, 0, 0, 0, 0 }; bf_key_st key = new bf_key_st(); key.P = new UInt32[16 + 2]; key.S = new UInt32[4 * 256]; _key = Marshal.AllocHGlobal(key.P.Length * sizeof(UInt32) + key.S.Length * sizeof(UInt32)); Marshal.StructureToPtr(key, _key, false); _encryptNum = 0; _decryptNum = 0; }
public void Dispose() { Marshal.FreeHGlobal(_key); }
public void SetKey(byte[] data) { _encryptNum = 0; _decryptNum = 0; BF_set_key(_key, data.Length, data); }
public byte[] Encrypt(byte[] buffer) { byte[] ret = new byte[buffer.Length]; switch (_algorithm) { case BlowfishAlgorithm.ECB: BF_ecb_encrypt(buffer, ret, _key, 1); break; case BlowfishAlgorithm.CBC: BF_cbc_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, 1); break; case BlowfishAlgorithm.CFB64: BF_cfb64_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, ref _encryptNum, 1); break; case BlowfishAlgorithm.OFB64: BF_ofb64_encrypt(buffer, ret, buffer.Length, _key, _encryptIv, out _encryptNum); break; } return ret; }
public byte[] Decrypt(byte[] buffer) { byte[] ret = new byte[buffer.Length]; switch (_algorithm) { case BlowfishAlgorithm.ECB: BF_ecb_encrypt(buffer, ret, _key, 0); break; case BlowfishAlgorithm.CBC: BF_cbc_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, 0); break; case BlowfishAlgorithm.CFB64: BF_cfb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, ref _decryptNum, 0); break; case BlowfishAlgorithm.OFB64: BF_ofb64_encrypt(buffer, ret, buffer.Length, _key, _decryptIv, out _decryptNum); break; } return ret; }
public byte[] EncryptIV { get { return _encryptIv; } set { System.Buffer.BlockCopy(value, 0, _encryptIv, 0, 8); } }
public byte[] DecryptIV { get { return _decryptIv; } set { System.Buffer.BlockCopy(value, 0, _decryptIv, 0, 8); } } } } |
|
|
m-s 
      
Beiträge: 149
Erhaltene Danke: 7
Win 10
C# (VS 2015)
|
Verfasst: Mo 20.06.11 10:40
Habs gestern ne Stunde lang verwirrt versucht und nicht geschafft.
Kannst Du noch den Aufruf fürs Entschlüsseln posten 
_________________ Gruß Markus
|
|
Trashkid2000
      
Beiträge: 561
Erhaltene Danke: 137
|
Verfasst: Mo 20.06.11 10:54
Hi,
C#-Quelltext 1: 2: 3: 4: 5:
| using (Blowfish bf = new Blowfish(BlowfishAlgorithm.CFB64)) { bf.SetKey(Encoding.UTF8.GetBytes("Toller Key")); string decrypted = Encoding.UTF8.GetString(bf.Decrypt(Convert.FromBase64String(cryptedBase64))); } | cryptedBase64 ist dabei wied er Name schon sagt der verschlüsselte Text in Base64-Form
LG
Für diesen Beitrag haben gedankt: m-s
|
|
m-s 
      
Beiträge: 149
Erhaltene Danke: 7
Win 10
C# (VS 2015)
|
Verfasst: Mo 20.06.11 11:06
Danke, da kann ich mich ja endlich ran machen und ne Software schreiben, die mit WebOS verschlüsselte Daten austauschen kann.
_________________ Gruß Markus
|
|
|