コード例 #1
0
        public StratisBlockData CertifyUser(string emailAddress, string moocEmailAddress, MicroCredential MicroCredential)
        {
            var block = new StratisBlockData(DateTime.Now, new List <Transactions> {
                new Transactions(moocEmailAddress, emailAddress, MicroCredential.CertificateFee)
                {
                    MicroCredentials = new List <MicroCredential> {
                        new MicroCredential {
                            MicroCredentialId = MicroCredential.MicroCredentialId,
                            /*MicroCredentialDescription = MicroCredential.MicroCredentialDescription,*/
                            MicroCredentialName = MicroCredential.MicroCredentialName
                        }
                    }
                }
            });

            //Get RSAKeysFromDB

            var moocProvider = RepositoryEndPointService.GetMoocProviderFromDB();

            RestoreMoocKeys(moocProvider);
            //Note We Sign with Mooc's Public Key. and Expose Private Key to the other parites to verify Mooc's Signature!!
            block.KeyModulus    = moocProvider.MoocModulus;   //Rsa316Engine.getModValue();
            block.MoocPublicKey = moocProvider.MoocPublicKey; //Rsa316Engine.getPublicKey();

            block.MoocSignature = CreateSignature(block);
            return(block);
        }
コード例 #2
0
        private void RestoreMoocKeys(MoocProvider moocProvider)
        {
            if (moocProvider == null)
            {
                throw new KeyNotFoundException("Mooc Provider Does not Exist");
            }
            if (moocProvider.MoocModulus == null || moocProvider.MoocPublicKey == null || moocProvider.MoocPrivateKey == null)
            {
                Rsa316Engine.generateNewKey();
                moocProvider.MoocPrivateKey = Rsa316Engine.getPrivateKey();
                moocProvider.MoocPublicKey  = Rsa316Engine.getPublicKey();
                moocProvider.MoocModulus    = Rsa316Engine.getModValue();

                //Encrypt with Private Key: therefore swap RsaEngineKeys:
                byte[] temp = Rsa316Engine.getPrivateKey();
                Rsa316Engine.setPrivateKey(Rsa316Engine.getPublicKey());
                Rsa316Engine.setPublicKey(temp);

                RepositoryEndPointService.UpdateMoocProviderKeys(moocProvider);
            }
            else
            {
                //Encrypt with Private Key: therefore swap RsaEngineKeys:
                byte[] temp = moocProvider.MoocPrivateKey;
                Rsa316Engine.setPrivateKey(moocProvider.MoocPublicKey);
                Rsa316Engine.setPublicKey(temp);
                Rsa316Engine.setModValue(moocProvider.MoocModulus);
            }
        }
コード例 #3
0
        public string CreateSignature(string stratisBlockDataToSign)
        {
            var moocProvider = RepositoryEndPointService.GetMoocProviderFromDB();

            RestoreMoocKeys(moocProvider);

            //Note: We are signing with Private Key
            var signBytes = Rsa316Engine.Encrypt(stratisBlockDataToSign);

            return(Convert.ToBase64String(signBytes));
        }
コード例 #4
0
        public bool VerifyUserCert(string emailAddress, MicroCredential microCredential)
        {
            Candidate candidate = RepositoryEndPointService.GetCandidateByEmail(emailAddress);
            CandidateMicroCredentialCourse candidateWithCourse = RepositoryEndPointService.GetCandidateAndCourseForVerification(candidate.CandidateId, microCredential.MicroCredentialId);

            if (candidateWithCourse == null)
            {
                return(false);
            }

            var hashOfMicroCredential = candidateWithCourse.HashOfMine;
            var moocProvider          = RepositoryEndPointService.GetMoocProviderById(microCredential.MoocProviderId);

            if (moocProvider == null)
            {
                throw new Exception("No Mooc Course Provider for this course!");
            }
            //return this.StratisApiFullfilRequestComponent.VerifyBlockData(new VerifyBlockRequest { externalAddress = ConfigurationManager.AppSettings["ExternalAddress"], message = this.MoocProvider.GetUserDataToCertify(candidate.EmailAddress, this.MoocProvider.Mooc.EmailAddress, microCredential), signature = hashOfMicroCredential }).Result;
            var moocEmailAddress = moocProvider.EmailAddress;
            var content          = this.GetUserDataToCertify(emailAddress, moocEmailAddress, microCredential);
            var signedContent    = this.CreateSignature(content);

            return(candidateWithCourse.HashOfMine.Equals(signedContent));
        }
コード例 #5
0
 public void AddUserToMicroCredentialCourse(string emailAddress, MicroCredential microCredential)
 {
     RepositoryEndPointService.EnroleUserToMicroCredentialCourseUsingEmailId(emailAddress, microCredential.MicroCredentialId);
 }
コード例 #6
0
 public List <MicroCredential> GetAllMicroCredentials()
 {
     return(RepositoryEndPointService.GetAllMicroCredentials());
 }