예제 #1
0
파일: Session.cs 프로젝트: zr40/kyru-dotnet
        /// <summary>
        /// Constructor of Session class for a new User
        /// </summary>
        /// <param name="username">Username of the user</param>
        /// <param name="password">Password of the user</param>
        /// <param name="localObjectStorage">LocalObjectStorage</param>
        internal Session(string username, string password, LocalObjectStorage localObjectStorage)
        {
            LocalObjectStorage = localObjectStorage;

            rsaKeyPair = Crypto.DeriveRsaKey(Encoding.UTF8.GetBytes(username), Encoding.UTF8.GetBytes(password));

            KademliaId id = Crypto.Hash(rsaKeyPair.Public);

            Username = username;
            User = localObjectStorage.GetObject(id) as User;
            if (User == null)
            {
                User = new User(rsaKeyPair.Public) {ObjectId = id};
                localObjectStorage.StoreObject(User, true);
            }

            onUserUpdated = UpdateUser;
            localObjectStorage.OnUserUpdated += onUserUpdated;
        }
예제 #2
0
파일: Crypto.cs 프로젝트: zr40/kyru-dotnet
 /// <summary>
 /// Generates a signature for the data
 /// </summary>
 /// <param name="data">Data to sign</param>
 /// <returns>The signature of the hashed data</returns>
 internal static byte[] Sign(byte[] data, RsaKeyPair keyPair)
 {
     return DecryptRsa(Hash(data), keyPair);
 }
예제 #3
0
파일: Crypto.cs 프로젝트: zr40/kyru-dotnet
 /// <summary>
 /// Decrypts data with an RSA key pair
 /// </summary>
 /// <param name="data">Data to decrypt</param>
 /// <param name="keyPair">RSA Key pair to use for decryption</param>
 /// <returns>The decrypted data</returns>
 internal static byte[] DecryptRsa(byte[] data, RsaKeyPair keyPair)
 {
     var c = new BigInt(data);
     var d = new BigInt(keyPair.Private);
     var n = new BigInt(keyPair.Public);
     return c.PowerMod(d, n).ToByteArray();
 }