我正在尝试使用Java代码中的JSch库将SSH SSH到EC2。我在SO中引用了此链接如何使用JSch库在ec2连接中将.pem文件内容用作字符串并尝试了下面提到的几件事,但没有成功。有人可以指导我如何实现我的目标吗?
目的
我有一个像这样的PEM文件。我不想将我的PEM文件存储在AWS中的任何位置,因此我的方法是提取一个等效字符串,我可以对其进行编码和存储在数据库中,然后从Java对其进行解码,以将参数传递给addIdentity采用以下参数的方法:
addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
throws JSchException
Run Code Online (Sandbox Code Playgroud)
addIdentity(String name, byte[] prvkey, byte[] pubkey, byte[] passphrase)
throws JSchException
Run Code Online (Sandbox Code Playgroud)
出于我的目标,我addIdentity相信我的方法是这样的:
addIdentity ("username","{privatekey string converted to byte array}",null, null)
Run Code Online (Sandbox Code Playgroud)
我试图了解如何形成字符串?我对密码学非常陌生,但是在此过程中,我了解到由于PEM具有BEGIN RSA PRIVATE KEY,它是PKCS1格式。JSch是否支持PKCS1格式,或者需要将其转换为PKSC8?
其次,我了解到主体是使用Base64编码的,因此我什至在剥离所有回车符,页眉和页脚后甚至尝试使用Base64解码字符串,这给了我这样的错误
线程“主”中的异常java.security.spec.InvalidKeySpecException:java.security.InvalidKeyException:IOException:algid解析错误,不是序列
以下是我尝试跟进但仍无法解决的一些其他链接。
希望有人可以指引我正确的方向。
谢谢!
尝试使用下面的cli命令创建一个cloudformation堆栈时出现以下错误.
aws cloudformation create-stack --stack-name subodh-local-stack --template-url s3URL/template.json --parameters s3URL/params.json
Run Code Online (Sandbox Code Playgroud)
错误:awscli.argprocess.ParamError:解析参数'--parameters'时出错:无法检索https://s3.amazonaws.com/ //params.json:收到非200状态代码403 2017-08-18 01: 32:31,309 - MainThread - awscli.clidriver - DEBUG - 以rc 255退出
template.json:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"Type": "AWS::Lambda::Function",
"Properties": {
"FunctionName": {
"Ref": "LambdaFunctionName"
},
"Handler": {
"Ref": "LambdaHandler"
},
"Role": {
"Ref": "LambdaExecutionRoleArn"
},
"Code": {
"S3Bucket": {
"Ref": "LambdaSourceBucket"
},
"S3Key": {
"Ref": "LambdaSourceKey"
}
},
"SubnetID": {
"Ref": "LambdaSubnetID"
},
"Runtime": "nodejs4.3",
"Timeout": "25",
"MemorySize": "128",
"VpcConfig": "vpc-2323454f",
"securityGroupID": "sg-0sdfs17g"
} …Run Code Online (Sandbox Code Playgroud) 我有一个名为“lastModified”的列,其中包含如下所示的字符串,表示 GMT 时间。 “2019-06-24T15:36:16.000Z”
我想使用 scala 将此字符串格式化为 Spark 中的yyyy-MM-dd HH:mm:ss格式。为了实现这一目标,我创建了一个带有新列“ConvertedTS”的数据框。这给出了不正确的时间。
我运行的机器位于美国/纽约时区。
df.withColumn("ConvertedTS", date_format(to_utc_timestamp(to_timestamp(col("lastModified"), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"), "America/New_York"), "yyyy-MM-dd HH:MM:SS").cast(StringType))
Run Code Online (Sandbox Code Playgroud)
我基本上是在寻找 yyyy-MM-dd HH:mm:ss 中以下语句的结果格式
df.withColumn("LastModifiedTS", col("lastModified"))
Run Code Online (Sandbox Code Playgroud)
目前对我有用的方法之一是 udf,但由于不推荐使用 udf,我一直在寻找更多可以使用的直接表达式。
val convertToTimestamp = (logTimestamp: String) => {
println("logTimeStamp: " + logTimestamp)
var newDate = ""
try {
val sourceFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
sourceFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
val convertedDate = sourceFormat.parse(logTimestamp)
val destFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
destFormat.setTimeZone(TimeZone.getTimeZone("GMT"))
newDate = destFormat.format(convertedDate)
println("newDate: " + newDate)
} catch {
case e: Exception => e.printStackTrace()
} …Run Code Online (Sandbox Code Playgroud) scala user-defined-functions dataframe apache-spark apache-spark-sql
apache-spark ×1
aws-cli ×1
cryptography ×1
dataframe ×1
java ×1
jsch ×1
pem ×1
rsa ×1
scala ×1