public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) { if (signature == null) { throw new ArgumentNullException(nameof(signature)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (publicKey == null) { throw new ArgumentNullException(nameof(publicKey)); } if (signature.Length != SignatureSizeInBytes) { throw new ArgumentException($"Signature size must be {SignatureSizeInBytes}", nameof(signature)); } if (publicKey.Length != PublicKeySizeInBytes) { throw new ArgumentException($"Public key size must be {PublicKeySizeInBytes}", nameof(signature)); } return(Ed25519Operations.CryptoSignVerify(signature, 0, message, 0, message.Length, publicKey, 0)); }
/// <summary> /// Verify Ed25519 signature /// </summary> /// <param name="signature">Signature bytes</param> /// <param name="message">Message</param> /// <param name="publicKey">Public key</param> /// <returns>True if signature is valid, false if it's not</returns> public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) { Contract.Requires <ArgumentNullException>(signature != null && message != null && publicKey != null); Contract.Requires <ArgumentException>(signature.Length == SignatureSize && publicKey.Length == PublicKeySize); return(Ed25519Operations.crypto_sign_verify(signature, 0, message, 0, message.Length, publicKey, 0)); }
/// <summary> /// Calculate key pair from the key seed. /// </summary> /// <param name="publicKey">Public key</param> /// <param name="expandedPrivateKey">Expanded form of the private key</param> /// <param name="privateKeySeed">Private key seed value</param> public static void KeyPairFromSeed(ArraySegment <byte> publicKey, ArraySegment <byte> expandedPrivateKey, ArraySegment <byte> privateKeySeed) { Ed25519Operations.crypto_sign_keypair( publicKey.Array, publicKey.Offset, expandedPrivateKey.Array, expandedPrivateKey.Offset, privateKeySeed.Array, privateKeySeed.Offset); }
public static void Sign(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> expandedPrivateKey) { if (signature.Array == null) { throw new ArgumentNullException("signature.Array"); } if (signature.Count != SignatureSizeInBytes) { throw new ArgumentException("signature.Count"); } if (expandedPrivateKey.Array == null) { throw new ArgumentNullException("expandedPrivateKey.Array"); } if (expandedPrivateKey.Count != ExpandedPrivateKeySizeInBytes) { throw new ArgumentException("expandedPrivateKey.Count"); } if (message.Array == null) { throw new ArgumentNullException("message.Array"); } Ed25519Operations.crypto_sign2(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset); }
/// <summary> /// Create new Ed25519 signature /// </summary> /// <param name="signature">Buffer for signature</param> /// <param name="message">Message bytes</param> /// <param name="expandedPrivateKey">Expanded form of private key</param> public static void Sign(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> expandedPrivateKey) { Contract.Requires <ArgumentNullException>(signature.Array != null && message.Array != null && expandedPrivateKey.Array != null); Contract.Requires <ArgumentException>(expandedPrivateKey.Count == ExpandedPrivateKeySize); Ed25519Operations.crypto_sign(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset); }
public static void KeyPairFromSeed(ArraySegment <byte> publicKey, ArraySegment <byte> expandedPrivateKey, ArraySegment <byte> privateKeySeed) { if (publicKey.Array == null) { throw new ArgumentNullException("publicKey.Array"); } if (expandedPrivateKey.Array == null) { throw new ArgumentNullException("expandedPrivateKey.Array"); } if (privateKeySeed.Array == null) { throw new ArgumentNullException("privateKeySeed.Array"); } if (publicKey.Count != PublicKeySizeInBytes) { throw new ArgumentException("publicKey.Count"); } if (expandedPrivateKey.Count != ExpandedPrivateKeySizeInBytes) { throw new ArgumentException("expandedPrivateKey.Count"); } if (privateKeySeed.Count != PrivateKeySeedSizeInBytes) { throw new ArgumentException("privateKeySeed.Count"); } Ed25519Operations.crypto_sign_keypair( publicKey.Array, publicKey.Offset, expandedPrivateKey.Array, expandedPrivateKey.Offset, privateKeySeed.Array, privateKeySeed.Offset); }
public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) { if (signature == null) { throw new ArgumentNullException(nameof(signature)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (publicKey == null) { throw new ArgumentNullException(nameof(publicKey)); } if (signature.Length != SignatureSizeInBytes) { throw new ArgumentException(string.Format("Signature size must be {0}", SignatureSizeInBytes), "signature.Length"); } if (publicKey.Length != PublicKeySizeInBytes) { throw new ArgumentException(string.Format("Public key size must be {0}", PublicKeySizeInBytes), "publicKey.Length"); } return(Ed25519Operations.crypto_sign_verify(signature, 0, message, 0, message.Length, publicKey, 0)); }
public static byte[] PublicKeyFromPrivateKey(byte[] privateKey) { byte[] publicKey = new byte[PublicKeySizeInBytes]; Ed25519Operations.crypto_sign_keypair(publicKey, 0, privateKey, 0); //CryptoBytes.Wipe(privateKey); return(publicKey); }
/// <summary> /// Calculate key pair from the key seed. /// </summary> /// <param name="publicKey">Public key</param> /// <param name="expandedPrivateKey">Expanded form of the private key</param> /// <param name="privateKeySeed">Private key seed value</param> public static void KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, byte[] privateKeySeed) { var pk = new byte[PublicKeySize]; var sk = new byte[ExpandedPrivateKeySize]; Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0); publicKey = pk; expandedPrivateKey = sk; }
public static void PublicKeyFromPrehashedPrivateKey(out byte[] publicKey, byte[] prehashedPrivateKey) { Contract.Requires <ArgumentNullException>(prehashedPrivateKey != null); Contract.Requires <ArgumentException>(prehashedPrivateKey.Length == ExpandedPrivateKeySize); var pk = new byte[PublicKeySize]; Ed25519Operations.crypto_sign_keypair_prehashed(pk, 0, prehashedPrivateKey, 0); publicKey = pk; }
/// <summary> /// Verify Ed25519 signature /// </summary> /// <param name="signature">Signature bytes</param> /// <param name="message">Message</param> /// <param name="publicKey">Public key</param> /// <returns>True if signature is valid, false if it's not</returns> public static bool Verify(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> publicKey) { // Contract.Requires<ArgumentException>(signature.Count == SignatureSize && publicKey.Count == PublicKeySize); if (signature.Count != SignatureSize || publicKey.Count != PublicKeySize) { throw new ArgumentException(); } return(Ed25519Operations.crypto_sign_verify(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, publicKey.Array, publicKey.Offset)); }
///// <summary> ///// Create new Ed25519 signature ///// </summary> ///// <param name="signature">Buffer for signature</param> ///// <param name="message">Message bytes</param> ///// <param name="expandedPrivateKey">Expanded form of private key</param> //public static void Sign(ArraySegment<byte> signature, ArraySegment<byte> message, ArraySegment<byte> expandedPrivateKey) { // Contract.Requires<ArgumentNullException>(signature.Array != null && message.Array != null && expandedPrivateKey.Array != null); // Contract.Requires<ArgumentException>(expandedPrivateKey.Count == ExpandedPrivateKeySize); // Ed25519Operations.crypto_sign(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset); //} ///// <summary> ///// Create new Ed25519 signature ///// </summary> ///// <param name="signature">Buffer for signature</param> ///// <param name="message">Message bytes</param> ///// <param name="expandedPrivateKey">Expanded form of private key</param> //public static byte[] Sign(byte[] message, byte[] expandedPrivateKey) { // Contract.Requires<ArgumentNullException>(message != null && expandedPrivateKey != null); // Contract.Requires<ArgumentException>(expandedPrivateKey.Length == ExpandedPrivateKeySize); // var signature = new byte[SignatureSize]; // Sign(new ArraySegment<byte>(signature), new ArraySegment<byte>(message), new ArraySegment<byte>(expandedPrivateKey)); // return signature; //} public static byte[] SignWithPrehashed(byte[] message, byte[] privateKey, byte[] publicKey) { Contract.Requires <ArgumentNullException>(message != null && privateKey != null && publicKey != null); Contract.Requires <ArgumentException>(privateKey.Length == ExpandedPrivateKeySize); Contract.Requires <ArgumentException>(publicKey.Length == PublicKeySize); var signature = new byte[SignatureSize]; Ed25519Operations.crypto_sign_prehashed(signature, message, message.Length, privateKey, publicKey); return(signature); }
/// <summary> /// Calculate key pair from the key seed. /// </summary> /// <param name="publicKey">Public key</param> /// <param name="expandedPrivateKey">Expanded form of the private key</param> /// <param name="privateKeySeed">Private key seed value</param> public static void KeyPairFromSeed(ArraySegment <byte> publicKey, ArraySegment <byte> expandedPrivateKey, ArraySegment <byte> privateKeySeed) { Contract.Requires <ArgumentNullException>(publicKey.Array != null && expandedPrivateKey.Array != null && privateKeySeed.Array != null); Contract.Requires <ArgumentException>(expandedPrivateKey.Count == ExpandedPrivateKeySize && privateKeySeed.Count == PrivateKeySeedSize); Contract.Requires <ArgumentException>(publicKey.Count == PublicKeySize); Ed25519Operations.crypto_sign_keypair( publicKey.Array, publicKey.Offset, expandedPrivateKey.Array, expandedPrivateKey.Offset, privateKeySeed.Array, privateKeySeed.Offset); }
public static void Sign(Span <byte> signature, ReadOnlySpan <byte> message, ReadOnlySpan <byte> expandedPrivateKey) { if (signature.Length != SignatureSizeInBytes) { throw new ArgumentException($"Signature size must be {SignatureSizeInBytes}", nameof(signature)); } if (expandedPrivateKey.Length != ExpandedPrivateKeySizeInBytes) { throw new ArgumentException($"Private key size must be {ExpandedPrivateKeySizeInBytes}", nameof(expandedPrivateKey)); } Ed25519Operations.crypto_sign2(signature, message, expandedPrivateKey); }
public static bool Verify(ReadOnlySpan <byte> signature, ReadOnlySpan <byte> message, ReadOnlySpan <byte> publicKey) { if (signature.Length != SignatureSizeInBytes) { throw new ArgumentException($"Signature size must be {SignatureSizeInBytes}", nameof(signature)); } if (publicKey.Length != PublicKeySizeInBytes) { throw new ArgumentException($"Public key size must be {PublicKeySizeInBytes}", nameof(signature)); } return(Ed25519Operations.crypto_sign_verify(signature, message, publicKey)); }
/// <summary> /// Encodes the specified private key. /// </summary> /// <param name="privateKey">The private key.</param> /// <param name="publicKey">The pub key.</param> /// <param name="msg">The MSG.</param> /// <param name="iv">The iv.</param> /// <param name="salt">The salt.</param> /// <returns>System.String.</returns> internal static string _Encode(byte[] privateKey, byte[] publicKey, string msg, byte[] iv, byte[] salt) { var shared = new byte[32]; Ed25519Operations.key_derive( shared, salt, privateKey, publicKey); return(salt.ToHexLower() + AesEncryptor(shared, iv, msg)); }
public static bool Verify(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> publicKey) { if (signature.Count != SignatureSizeInBytes) { throw new ArgumentException(string.Format("Signature size must be {0}", SignatureSizeInBytes), "signature.Count"); } if (publicKey.Count != PublicKeySizeInBytes) { throw new ArgumentException(string.Format("Public key size must be {0}", PublicKeySizeInBytes), "publicKey.Count"); } return(Ed25519Operations.crypto_sign_verify(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, publicKey.Array, publicKey.Offset)); }
/// <summary> /// Calculate key pair from the key seed. /// </summary> /// <param name="publicKey">Public key</param> /// <param name="expandedPrivateKey">Expanded form of the private key</param> /// <param name="privateKeySeed">Private key seed value</param> public static void KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, byte[] privateKeySeed) { Contract.Requires <ArgumentNullException>(privateKeySeed != null); Contract.Requires <ArgumentException>(privateKeySeed.Length == PrivateKeySeedSize); var pk = new byte[PublicKeySize]; var sk = new byte[ExpandedPrivateKeySize]; Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0); publicKey = pk; expandedPrivateKey = sk; }
/// <summary> /// Verify Ed25519 signature /// </summary> /// <param name="signature">Signature bytes</param> /// <param name="message">Message</param> /// <param name="publicKey">Public key</param> /// <returns>True if signature is valid, false if it's not</returns> public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) { // Contract.Requires<ArgumentNullException>(signature != null && message != null && publicKey != null); if (signature == null || message == null || publicKey == null) { throw new ArgumentException(); } // Contract.Requires<ArgumentException>(signature.Length == SignatureSize && publicKey.Length == PublicKeySize); if (signature.Length != SignatureSize || publicKey.Length != PublicKeySize) { throw new ArgumentException(); } return(Ed25519Operations.crypto_sign_verify(signature, 0, message, 0, message.Length, publicKey, 0)); }
/// <summary> /// Decodes the specified private key. /// </summary> /// <param name="privateKey">The private key.</param> /// <param name="publicKey">The pub key.</param> /// <param name="data">The data.</param> /// <returns>System.String.</returns> internal static string _Decode(byte[] privateKey, byte[] publicKey, byte[] data) { var salt = data.Take(0, 32).ToArray(); var iv = data.Take(32, 16); var payload = data.Take(48, data.Length - 48); var shared = new byte[32]; Ed25519Operations.key_derive( shared, salt, privateKey, publicKey); return(AesDecryptor(shared, iv, payload)); }
public static byte[] SecretKeyFromSeed(byte[] privateKeySeed) { if (privateKeySeed == null) { throw new ArgumentNullException("privateKeySeed"); } if (privateKeySeed.Length != PrivateKeySeedSizeInBytes) { throw new ArgumentException("privateKeySeed"); } byte[] sk = new byte[PrivateKeySeedSizeInBytes]; Ed25519Operations.crypto_secret_key_from_seed(sk, 0, privateKeySeed, 0); return(sk); }
public static void KeyPairFromSeed(Span <byte> publicKey, Span <byte> expandedPrivateKey, ReadOnlySpan <byte> privateKeySeed) { if (publicKey.Length != PublicKeySizeInBytes) { throw new ArgumentException("publicKey.Count"); } if (expandedPrivateKey.Length != ExpandedPrivateKeySizeInBytes) { throw new ArgumentException("expandedPrivateKey.Count"); } if (privateKeySeed.Length != PrivateKeySeedSizeInBytes) { throw new ArgumentException("privateKeySeed.Count"); } Ed25519Operations.crypto_sign_keypair(publicKey, expandedPrivateKey, privateKeySeed); }
public static void KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, byte[] privateKeySeed) { if (privateKeySeed == null) { throw new ArgumentNullException("privateKeySeed"); } if (privateKeySeed.Length != PrivateKeySeedSizeInBytes) { throw new ArgumentException("privateKeySeed"); } var pk = new byte[PublicKeySizeInBytes]; var sk = new byte[ExpandedPrivateKeySizeInBytes]; Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0); publicKey = pk; expandedPrivateKey = sk; }
internal static void KeyPairFromSeed(out byte[] internalKey, out byte[] expandedPrivateKey, byte[] privateKeySeed) { if (privateKeySeed == null) { throw new ArgumentNullException(nameof(privateKeySeed)); } if (privateKeySeed.Length != 32 && privateKeySeed.Length != 33) { throw new ArgumentException("privateKeySeed"); } var pk = new byte[internalKeySizeInBytes]; var sk = new byte[ExpandedPrivateKeySizeInBytes]; Ed25519Operations.crypto_sign_keypair(pk, 0, sk, 0, privateKeySeed, 0); internalKey = pk; expandedPrivateKey = sk; }
/// <summary> /// Verify Ed25519 signature /// </summary> /// <param name="signature">Signature bytes</param> /// <param name="message">Message</param> /// <param name="publicKey">Public key</param> /// <returns>True if signature is valid, false if it's not</returns> public static bool Verify(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> publicKey) { return(Ed25519Operations.crypto_sign_verify(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, publicKey.Array, publicKey.Offset)); }
/// <summary> /// Verify Ed25519 signature /// </summary> /// <param name="signature">Signature bytes</param> /// <param name="message">Message</param> /// <param name="publicKey">Public key</param> /// <returns>True if signature is valid, false if it's not</returns> public static bool Verify(byte[] signature, byte[] message, byte[] publicKey) { return(Ed25519Operations.crypto_sign_verify(signature, 0, message, 0, message.Length, publicKey, 0)); }
/// <summary> /// Create new Ed25519 signature /// </summary> /// <param name="signature">Buffer for signature</param> /// <param name="message">Message bytes</param> /// <param name="expandedPrivateKey">Expanded form of private key</param> public static void Sign(ArraySegment <byte> signature, ArraySegment <byte> message, ArraySegment <byte> expandedPrivateKey) { Ed25519Operations.crypto_sign(signature.Array, signature.Offset, message.Array, message.Offset, message.Count, expandedPrivateKey.Array, expandedPrivateKey.Offset); }