private async Task <bool> loadKeys(FunctionContext <dynamic> fc) { fc.Log.LogInformation("Loading Keys"); TableOperation getLatestKey = TableOperation.Retrieve <PrivateKeyTE>("ACCESS_PRIVATE", "LATEST"); TableResult result = await fc.Table.ExecuteAsync(getLatestKey); PrivateKeyTE pke = result.Result as PrivateKeyTE; if (pke == null) { fc.Log.LogInformation("No private key found."); return(false); } else { fc.Log.LogInformation("Private Key found with PKID: {PublicKeyId}", pke.PublicKeyId); if (pke.Expires != null && DateTime.Now < pke.Expires) { this.keyId = pke.PublicKeyId; RSA rsa = RSA.Create(); rsa.ImportRSAPrivateKey(Convert.FromBase64String(pke.PrivateKey), out _); this.privateRSAKey = rsa; return(true); } else { fc.Log.LogInformation("Private Key is expired!"); return(false); } } }
private async Task storePrivateKey(FunctionContext <dynamic> fc, byte[] privateKeyAsBytes, DateTime expiresIn) { PrivateKeyTE pk = new PrivateKeyTE(); pk.PartitionKey = "ACCESS_PRIVATE"; pk.RowKey = "LATEST"; pk.PublicKeyId = this.keyId; pk.Expires = expiresIn; pk.AssignePrivateKey(privateKeyAsBytes); TableOperation insertOrMerge = TableOperation.InsertOrReplace(pk); await fc.Table.ExecuteAsync(insertOrMerge); }