Skip to content

Instantly share code, notes, and snippets.

View open-ruic's full-sized avatar

Rui C. open-ruic

View GitHub Profile
@open-ruic
open-ruic / AddCertToAzureADApp.ps1
Created January 8, 2019 09:39
Add Certificate Key to Azure AD Application for Certificate Authentication
Param
(
[Parameter(ParameterSetName='Setting', Mandatory=$true)]
[String]
$SubscriptionId,
[Parameter(ParameterSetName='Setting', Mandatory=$true)]
[String]
$UserName,
@open-ruic
open-ruic / Send and Recevice Message from Azure Iothub using Paho MQTT for Python
Created August 9, 2017 09:28
Send and Recevice Message from Azure Iothub using Paho MQTT for Python
import base64
import hmac
import urllib.parse
import paho.mqtt.client as mqtt
import time
hubAddress = "freeiottest.azure-devices.cn"
deviceId = "myDeviceId"
deviceKey = '<your device key>'
@open-ruic
open-ruic / Create Secure Service Fabric with Custom Domain using ARM Template
Last active July 4, 2017 04:31
Create Secure Service Fabric with Custom Domain using ARM Template
一般情况下,如果我们没有为Azure Service Fabric开启群集安全证书功能,我们只需要将域名的DNS解析绑定到Service Fabric群集使用的负载均衡器对应的公网IP上即可。
但对于开启了安全证书功能的群集,我们需要将证书和域名进行绑定,相对要麻烦一些。
1. 生成证书
我们可以在CA申请自定义域名的可信证书,也可以使用自签名证书,无论哪种证书,我们都需要将证书使用者的名称和自定义域名保持一致。
借助Github上的PowerShell模块生成证书并上传KeyVault。
下载地址:https://github.com/ChackDan/Service-Fabric/tree/master/Scripts/ServiceFabricRPHelpers
Import-Module "C:\..\ServiceFabricRPHelpers\ServiceFabricRPHelpers.psm1"
$ResouceGroup = "kevin-group"
@open-ruic
open-ruic / Program.cs
Last active February 11, 2020 18:30
C# RSA Key Utils
using System;
namespace PKCS1ToPKCS8Application
{
class Program
{
static void Main(string[] args)
{
byte[] importedPrivateKeyBytes = Convert.FromBase64String("MIIEowIBAAKCAQEAtuHuMvnE3fYz/eom8mF7xxLXPETjfUpVYHL6AUVwXKKCrZ6uFszh2bY7ADoiIpuPTS0NVNYeKLlu6T59qzyr0bnT8KgXdZJFVzYWIh8VOLTb2zghlu8BeBoJP9t/a34Mj7gGJUZWBgECopEGCXrFwyIvXSW0JU5YrJinyyPhUjUXLeyowJUXoLwEafOHBRRiZZv1SNlntQOAenHFB/1uv2Y5xmdHm7xl+jjeo469u+pY535RCekmam9hWbZcn/WZEf9BZEmE2i4v7Qj72V92LrSUSSjF6w6lgU3B+Byu0XR8ZeUjD+FP9ZKvJyEtxlxOVaADQ+/udghUr1PnfXIHRQIDAQABAoIBAHG1UBFJ0unfJrx9VfHmQruoL0M94eQIz8TEOEWKEy7FrFKfEscCZHqlH1Io0wiJiDQICv3wk5fmk9taC3DorDweOnSrTsq/Q3XSHzjf8qXrbbeD0v6xZEx0g8O8iiEfolfJp6iNbvcUsbq6SPKj70pAewqDYtq/N8s4rztS98nQQ5PAQ10Zv3X910lc0vnPlPKew4y7w6hwb/pbiEBLbbV9tYAVaAm63n/EYxjo3UCRA0BJZxhJbRdEQzCEzClXlo6txx7nGQz/omv574P22ASCAfyrFNhaT20DR+ilIXe+edBpJehD6Q/lpO56STawb9xCAk6+aerM5dcIBMTETRECgYEA3RdnfpY1Z8KtOT1rVUeI094vylP1HONrcXNSsV0sbNPSwoK91UpO0mfsLLWxLtjvX52yixhfKxQ0QLYq3nyC8SRj2GE07aO1HZ81MI/9Y6ynJkw+
@open-ruic
open-ruic / AutoScanFeature
Last active June 6, 2018 08:58
Using HK2 with Jersey enabled autoscanning
import org.glassfish.hk2.api.JustInTimeInjectionResolver;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import javax.inject.Singleton;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
public class AutoScanFeature implements Feature {
@Override
@open-ruic
open-ruic / Upgrade Azure SQLDatabase with Restful API
Created February 27, 2017 08:39
Upgrade Azure SQLDatabase with Restful API
import com.microsoft.aad.adal4j.AuthenticationContext;
import com.microsoft.aad.adal4j.AuthenticationResult;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import javax.naming.ServiceUnavailableException;
import javax.net.ssl.HttpsURLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@open-ruic
open-ruic / Manage VirtualMachine with Azure SDK for JAVA 0.9.1
Last active February 27, 2017 08:36
Manage VirtualMachine with Azure SDK for JAVA 0.9.1
import com.microsoft.azure.management.compute.ComputeManagementClient;
import com.microsoft.azure.management.compute.ComputeManagementService;
import com.microsoft.azure.management.compute.models.*;
import com.microsoft.azure.management.network.NetworkResourceProviderClient;
import com.microsoft.azure.management.network.NetworkResourceProviderService;
import com.microsoft.azure.management.network.models.*;
import com.microsoft.azure.utility.AuthHelper;
import com.microsoft.windowsazure.Configuration;
import com.microsoft.windowsazure.exception.ServiceException;
import com.microsoft.windowsazure.management.configuration.ManagementConfiguration;
@open-ruic
open-ruic / Manage VirtualMachine with Azure SDK for JAVA 1.0
Last active February 27, 2017 08:35
azure sdk for java 1.0 usage
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.credentials.ApplicationTokenCredentials;
import com.microsoft.azure.management.Azure;
import com.microsoft.azure.management.compute.KnownWindowsVirtualMachineImage;
import com.microsoft.azure.management.compute.VirtualMachine;
import com.microsoft.azure.management.compute.VirtualMachineSizeTypes;
import com.microsoft.azure.management.resources.ResourceGroup;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.vianet.azure.sdk.Application;