Convert multi-line ssh public key to one-line for .ssh/authorized_keys

I received a public key like this and I should add it to .ssh/authorized_keys:

---- BEGIN SSH2 PUBLIC KEY ---- Comment: "rsa-key-20190107" AAAAB3NzaC1yc2EAAAABJQAAAQEAucNIPbPoaEqyBAKtk3LTfM/hiZlWomTdQEf7 zUI4LGz91aZYIZNpWGTAUZKuFLdIEsktxQTNwEJNWMe2QocqQWyPGA+xL08ZP7Xk VEbVOyH0nQ3ZHptgmyH4y4+bbAWXAROL3078h2iwtsCO343VQKg1iSNvemnLafA5 9/RtkcCR8SxH+NEXcc8MwGOE9gLX2pph4bxrFz9R6yyw3oRGVLt4uU9BlD3+LXg1 plUzc2KZXEt8Zr04I0Fd865zyiB8Q+2ZEPvHf7MMaW66FRe4BXCI7LMh/voXi0C8 H4NDIu1GZr7dNxgbEO05ZnASMofpLDU6cq7LFVl0BQG8gt1hOw== ---- END SSH2 PUBLIC KEY ---- 

I guess that I can edit this file in vi and to create the corresponding one-liner which is required for .ssh/authorized_keys.

Is this true?

AFAIK this key was created according to this page: https://winscp.net/eng/docs/guide_public_key

Convert template type to derived type when calling a function?

Apologies if the title is incorrect, I couldn’t think of better wording. I have the following code

template <class E> void ResolveEntityHit(E& entity, Projectile& projectile) {     static_assert(std::is_base_of<Entity, E>::value, "entity must be of type Entity");      entity.DealDamage(projectile.GetProjectileDamage());      if (entity.IsDead()) {         DestroyEntity(entity); //here is the problem     }      m_projectileManager->DestroyProjectile(projectile); }  void DestroyEntity(Enemy & enemy) {     m_enemyManager->DestroyEnemy(enemy); }  void DestroyEntity(Bunker & bunker) {     m_bunkerManager->DestroyBunker(bunker); } 

I’m trying to avoid using dynamic_cast as I have read that this isn’t good practice. I’m trying to keep the ResolveEntityHit as basic as possible that can accept multiple types, but then I would like to branch off and do different things depending on which type the entity is. For example, I have my entities separated into different classes, and each class is responsible for removing/adding entities, so I would need to call the function on the correct manager to remove the entity.

The code above doesn’t compile and I get error C2664: 'void DestroyEntity(Bunker &)': cannot convert argument 1 from 'E' to 'Enemy &'

Hopefully it’s clear what I’m trying to achieve, but I’m asking is there a better way to do this in terms of design/architecture and without the use of dynamic_cast? Possibly through using templates?

Convert decimal to binary

This program converts a decimal number to a binary number. This is one of my first C programs and I am wondering if I have used the elements of this language properly. Suggestions for improvement are welcome.

#include <stdio.h> #include <string.h>  void print_out_reversed(char string[]) {     int index = strlen(string);      while (string[index] != '')         index--;      for (int i = index; i >= 0; i--)         putchar(string[i]);     putchar('\n'); }  void print_decimal_number_binary(int number) {     if (number == 0)     {         printf("0\n");         return;     }      char bits[sizeof(int) * 8 + 1] = {0};     int index = 0;      while (number > 0)     {         if (number % 2 == 0)         {             bits[index] = '0';         }         else         {             bits[index] = '1';         }         number = number / 2;         index++;     }      print_out_reversed(bits); }  int main() {     printf("enter number: ");     int number;     scanf("%i", &number);     print_decimal_number_binary(number); } 

How to convert swap partition from RAID1 to RAID0 using mdadm

How to convert linux SWAP memory from RAID1 to RAID0?

Start with:
2 exact size swap formatted partitions (/dev/sdc5 and /dev/sdd5) on 2 physically separate disks that are used via Software RAID
(named md127, located /dev/md/s) in RAID 1 (Mirroring)

cat /proc/mdstat 

would show for md127 something like:

md127 : active raid1 sdc5[2] sdd5[0]       7806976 blocks super 1.2 [2/2] [UU] 

The task is to use the same:
2 exact size swap formatted partitions (/dev/sdc5 and /dev/sdd5) on 2 physically separate disks that are used via Software RAID
(named md127, located /dev/md/s) in RAID 0 (Striping)

cat /proc/mdstat 

would show for md127 something like:

md127 : active raid0 sdc5[2] sdd5[0]       15613952 blocks super 1.2 64k chunks 

Convert SWAP /dev/md/s from RAID1 to RAID0 with mdadm

For this you need to know:

  • the difference between RAID0 and RAID1
  • when the Operating System uses SWAP partition (for ex: when you are about to run out of free available physical memory)
  • how to monitor the memory usage (via a tool like conky)

Convert ASN.1 key to openssl .pem to decrypt a message encoded in hex?

I have an ASN.1 type key:

308204a40201000282010100b3b77eb538f617a8441cdcf1fb133c1e73156894f1e049402d5c3ca7c74b69c6a8e81913dcfaeaee3e46bee05934ed21c23adc989729c189bf791da75b596ef41a325938205399ec0ca3aceea90238f3589b5b8427f8bae78b801e65d00a4fdd4905bfc650a79d596034b3dc20fd894202a9f718799d742e7df5defde553e3ab8e952e0f3047f73fe1e1c8ca8a66536cf2f0746a0f607de6dba0a8e3570ef83c03420a919a950a5a007597bf2f5cac8d096f3cacb0ca228a73500dd2bd08451effb7ab00c07d92f22607a740a394506a085ab0fb5627a20e6fbf122a9ab369ee2fb61c983620d848a72b16047f265468369ac449e9b4f07361af8e1019df7d570203010001028201010099ee83a329a4efe27a64d6829571863ef687d1ca31dad0231e3730e4ec7915a2c92df3bce5bc2dd9de91ae106f983bbc7ca6fa27e0e22d19955d621ee4c997959192aa84be7b9d0d684e11636273bae004771d4df706bee070c64e431a8c9a978962593ebdfab375c8479bfee26b0753f90027db58df9a91efe5d7185583232f6edaba4d2c6c797ff177eed7e6ee6424adc3af8352e61134265522f0a1334761845231e6708b630caf0ca24a77f597b3ec2e038172017f66b1e76c1cd99d2b5a6a29faab9ba42a89ec44b1ff20ee606f9e7f9556bd9a74e5c1b83d87317f2008ca7790b4f0218292f484ca40a3c3d64c541634bbcc903f1c2cac5971a6f957f102818100bf54486569e2ff77a4fad4e97efd0048978b1d2d5e7b4221c3def2ad6ca0427af42bbf592cf2439048d90eff248810ebf6faf67851c4b1c7dd646f5372e6e9eb46360f737cedba2cc0b5a288ceefcf408e576e8352c990c2470a363085328b4a76732c39251a16ba7d37e0ac14bcec879081214bbdb543acecb31a7d3e670f8502818100f07662fee84a2e05e6997a28dfacbbc160417640cb285d223626b656e0e6c22309d5adef3888b38ad172017d467453ee53e831e2a877f7836aa1a5c19e7443142d5c1dcafc092a2f5c3951458ee0c9cfa153f8eefe22b94e51608e98bd5b3609a3c9f870f09e08c7830df749d96bf0eded633fb1318da083bf2a440fec48fa2b0281804764e4eaeadb28a6f5aa1f9ecda30ce309a1808eb86dd81c8f61773edd84e3a9cbc9334acc69ce6a5db49952fdc7c440b8d5a6f8f8d223e0c7ad3d996f0bd987d09845a5bb9d5dd66b469bd2df1d3f42009b81828176f38c7b43c53acfc92f8ee6aa4d7b396c05c52b0a99ccbca44ec2bb5a6419463e0875d39175b5fc7e2a9d02818042946500b38ca68597bdf32712179fbd014bded43dec252d6dd4f633c3fde0cf16d00562f14258841d4df5bf9c1c6588ddceb2d15158363e3aee1b192b2881d23a650112cd0a3495fc711a61aa17ef88ffe06252ba271f2be2385c034a9ad0b1869a4ba1e9ddb80c95eaee07929de28dde66d6a1d758a193190138eb37bf5515028181008d99f0f0beffa8fad237540ed70199de7c6d9324505174115e41031957ec2999017e8b1c7d5f9889a62fe78e1d532dc5ef41fa694e49aca5d52987d8f70f96413506e4714e11006dbcec3c318d6211de7f8548b4b37abedd2b2f96b367b0ebcfd0166c6582a660ce9f79b74ef83bb0bbc87604fdefc3b2bfcb1215b2f9ca1d35 

And an hex encoded? I think, message:

4c0605e901b09d75c5f5befe7438d7246f988531cc7a39a59f24b9488d47dfae9fc8beb5117f34a316f9380607bf239ba6eca84da47a12d720986a8a0100a7e9d7028d7e423557055b9e250f271d6436018c58e79a8f26bac10768776f06dc1786dd7428b3c445b8993e884630b36cb2d300fa5dc1fe0eba9e433062d9d8a58f33bf6f93aa37298a5703ccbf71c93adea447f018e9f75bb43dbc528cfc9bed865a9ba43f926071dabc89ccca2e000f1a966855cc9816e45c0113edb55a700198d346a90487b5ff1191994973eb1b5252b22c6410aa70ea4e9c3ebd468ef273d7cf9d15b5824244cd25f252886d1edfe2d6f2caa5d5e00fd84597e3de192db41b 

I want to decrypt the message using the key, how is that possible?