Beispiel #1
0
 public static byte[] CalculateSignature(ECPrivateKey privateKey, byte[] message)
 {
     if (privateKey.GetKeyType () == DJB_TYPE) {
         var sign = Sodium.SecretKeyAuth.SignHmacSha256 (message, privateKey.Serialize ());
         return sign;
     } else {
         throw new Exception ("Unknown type");
     }
 }
Beispiel #2
0
        public static byte[] CalculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey)
        {
            if (publicKey.GetKeyType () != privateKey.GetKeyType ()) {
                throw new Exception ("Public and private keys must be of the same type!");
            }

            if (publicKey.GetKeyType () == DJB_TYPE) {
                var sK = privateKey.Serialize ();
                var typedPK = publicKey.Serialize ();

                var pK = new byte[typedPK.Length - 1];
                for (int i = 1; i < typedPK.Length; i++) {
                    pK [i - 1] = typedPK [i];
                }

                var shared = Sodium.ScalarMult.Mult (sK, pK);
                return shared;
            } else {
                throw new Exception ("Unknown type");
            }
        }