示例#1
0
        /// <summary>
        /// Derives session keys from four key pairs and stores them in intern variables.
        /// </summary>
        /// <returns>Void.</returns>
        /// <param name="ePPK">E PP.</param>
        /// <param name="ePK">E P.</param>
        /// <param name="iPK">I P.</param>
        /// <param name="ePOTK">E POT.</param>
        private void DeriveSessionKeys(KeyPair ePPK, KeyPair ePK, KeyPair iPK, KeyPair ePOTK)
        {
            sessionReceiveKey.key = LibsodiumEncryption.Hash(IEncryption.ConcatBytes(ePPK.secretKey, ePK.secretKey, iPK.secretKey, ePOTK.secretKey));
            sessionSendKey.key    = LibsodiumEncryption.Hash(IEncryption.ConcatBytes(ePPK.publicKey, ePK.publicKey, iPK.publicKey, ePOTK.publicKey));

            /*
             * NotificationHandler.Instance.ShowNotification("",
             * "sessionReceiveKey is : " + Convert.ToBase64String(sessionReceiveKey) +
             * " sessionSendKey is : " + Convert.ToBase64String(sessionSendKey) +
             * " ePPK s is : " + Convert.ToBase64String(ePPK.secretKey) +
             * " ePK s is : " + Convert.ToBase64String(ePK.secretKey) +
             * " iPK s is : " + Convert.ToBase64String(iPK.secretKey) +
             * " ePOTK s is : " + Convert.ToBase64String(ePOTK.secretKey) +
             * " ePPK is : " + Convert.ToBase64String(ePPK.publicKey) +
             * " ePK is : " + Convert.ToBase64String(ePK.publicKey) +
             * " iPK is : " + Convert.ToBase64String(iPK.publicKey) +
             * " ePOTK is : " + Convert.ToBase64String(ePOTK.publicKey));*/
        }
示例#2
0
 /// <summary>
 /// Advances the key.
 /// </summary>
 /// <returns>The key.</returns>
 /// <param name="key">Key.</param>
 public static byte[] AdvanceKey(byte[] key)
 {
     return(LibsodiumEncryption.Hash(IEncryption.ConcatBytes(key, new byte[] { 0x02 })));
 }
示例#3
0
 /// <summary>
 /// Gets the enc key from the chainkey.
 /// Does this by appending 0x01 to and hashing the current key
 /// </summary>
 /// <returns>The enc key from chain.</returns>
 /// <param name="chainKey">Chain key.</param>
 public static byte[] GetEncKeyFromChain(ChainKey chainKey)
 {
     return(LibsodiumEncryption.Hash(IEncryption.ConcatBytes(chainKey.key, new byte[] { 0x01 })));
 }
示例#4
0
 /// <summary>
 /// Converts a chain key to an Encryption key for actual usage
 /// </summary>
 /// <returns>The encryption key.</returns>
 /// <param name="chainKey">Chain key.</param>
 private byte[] ChainToEncryptionKey(byte[] chainKey)
 {
     return(LibsodiumEncryption.Hash(IEncryption.ConcatBytes(chainKey, new byte[] { 0x01 })));
 }
示例#5
0
 /// <summary>
 /// Validates a signature for given data
 /// </summary>
 /// <returns><c>true</c>, if vertify was successful, <c>false</c> otherwise.</returns>
 /// <param name="signature">Signature.</param>
 /// <param name="data">Data.</param>
 /// <param name="publicKey">Public key.</param>
 public override bool VertifySignatureDetached(byte[] signature, byte[] data, byte[] publicKey)
 {
     // skip the first byte at is only the indicator to the signature type
     return(LibsodiumEncryption.SignVertifyDetached(signature.Skip(1).ToArray(), data, publicKey));
 }
示例#6
0
 static LibsodiumEncryption()
 {
     Instance = new LibsodiumEncryption();
 }
示例#7
0
 /// <summary>
 /// Derives the encryption key from a passphrase.
 /// </summary>
 /// <param name="phrase">Phrase.</param>
 public void DeriveEncryptionKeyFromPassphrase(string phrase)
 {
     SetEncryptionKey(LibsodiumEncryption.Hash(System.Text.Encoding.UTF8.GetBytes(phrase)));
 }