小编Coo*_*ter的帖子

获取Terraform google_monitoring_notification_channel资源的Slack auth_token

我希望从gcloud-> slack设置一些警报,到目前为止,已经按照以下说明进行了测试并正在运行:

https://cloud.google.com/monitoring/support/notification-options?_ga=2.190773474.-879257953.1550134526#slack

但是,理想情况下,我会将这些通知的配置存储在terraform脚本中,这样,如果需要再次设置,则无需遵循手动步骤。看起来这应该可行:https//www.terraform.io/docs/providers/google/r/monitoring_notification_channel.html

我已经运行了gcloud alpha monitoring channel-descriptors describe projects/<My Project>/notificationChannelDescriptors/slack,它会为labels + type产生以下输出:

labels:
- description: A permanent authentication token provided by Slack. This field is obfuscated
    by returning only a few characters of the key when fetched.
  key: auth_token
- description: The Slack channel to which to post notifications.
  key: channel_name
type: slack
Run Code Online (Sandbox Code Playgroud)

因此,我认为通知渠道的Terraform配置希望是:

resource "google_monitoring_notification_channel" "basic" {
  display_name = "My slack notifications"
  type = "slack"
  labels = {
    auth_token = "????????"
    channel_name = …
Run Code Online (Sandbox Code Playgroud)

google-cloud-platform terraform slack stackdriver

7
推荐指数
1
解决办法
349
查看次数

非对称加密差异 - Android与Java

我最近开始编写一个用Java编写的在线游戏的Android版本.但是,我遇到了与加密不一致的问题.Java应用程序工作正常 - 它从文件读取公钥,加密一些文本并将其传递到服务器,在那里使用私钥正确解密.在android上,一切似乎都有效(并且正在运行相同的代码),但是服务器有一个BadPaddingException试图解密消息.我已经在下面列出了所有相关代码和一步一步的事件序列:

连接到服务器时发生的第一件事是对称密钥的协议.这是在客户端上生成的,因此:

SecretKey symmetricKey = null;
try
{
    KeyGenerator keyGen = KeyGenerator.getInstance("AES");
    symmetricKey = keyGen.generateKey();
}
catch (Throwable t)
{
    Debug.stackTrace(t, "Failed to generate symmetric key.");
}

return symmetricKey;
Run Code Online (Sandbox Code Playgroud)

然后将其转换为Base64字符串:

byte[] keyBytes = secretKey.getEncoded();
return base64Interface.encode(keyBytes);
Run Code Online (Sandbox Code Playgroud)

并使用公钥加密:

public static String encrypt(String messageString, Key key)
{
    String encryptedString = null;
    try
    {
        byte[] messageBytes = messageString.getBytes();
        String algorithm = key.getAlgorithm()
        Cipher cipher = Cipher.getInstance(algorithm);
        cipher.init(Cipher.ENCRYPT_MODE, key);
        byte[] cipherData = cipher.doFinal(messageBytes);
        encryptedString = base64Interface.encode(cipherData);

        //Strip out any newline characters
        encryptedString …
Run Code Online (Sandbox Code Playgroud)

java encryption android rsa

6
推荐指数
1
解决办法
947
查看次数