public static byte[] Decrypt(byte[] data, C25519Key key) { var size = data[1] & 127; var sizeLength = 0; var hasFieldSize = (data[1] & 128) != 0; if (hasFieldSize) { sizeLength = size; size = (int)new BigInteger(data.Skip(2).Take(sizeLength).ToArray(), true, true); } var step = 2 + sizeLength; var asymmetricCipher = data.Skip(step).Take(32 * 3).ToArray(); var asymmetricPlain = key.Decrypt(asymmetricCipher); step += AsymmetricSize; if (size == 200) { return(UnPad32(asymmetricPlain)); } var symmetricKey = AesSherableKey.Parse(asymmetricPlain); return(symmetricKey.Decrypt(data.Skip(step).ToArray())); }
public AesSherableKey GenKey(AesKey key) => AesSherableKey.Parse(key.Hash(ToByteArray()));