-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support of RPK to Leshan Client Demo
- Loading branch information
1 parent
a75f820
commit 208d8f5
Showing
5 changed files
with
177 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,6 @@ bin/ | |
# log Files # | ||
**/src/main/**/logback*.xml | ||
**/src/test/**/logback*.xml | ||
|
||
# Credentials files # | ||
**/*.der |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
leshan-core/src/main/java/org/eclipse/leshan/util/SecurityUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2018 Sierra Wireless and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* and the Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.html. | ||
* | ||
* Contributors: | ||
* Sierra Wireless - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.leshan.util; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.security.KeyFactory; | ||
import java.security.PrivateKey; | ||
import java.security.PublicKey; | ||
import java.security.spec.PKCS8EncodedKeySpec; | ||
import java.security.spec.X509EncodedKeySpec; | ||
|
||
public class SecurityUtil { | ||
|
||
/** | ||
* Extract Elliptic Curve private key in PKCS8 format from file (DER encoded). | ||
*/ | ||
public static PrivateKey extractPrivateKey(String fileName) throws Exception { | ||
byte[] keyBytes = Files.readAllBytes(Paths.get(fileName)); | ||
|
||
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); | ||
KeyFactory kf = KeyFactory.getInstance("EC"); | ||
return kf.generatePrivate(spec); | ||
} | ||
|
||
/** | ||
* Extract Elliptic Curve public key in SubjectPublicKeyInfo format from file (DER encoded). | ||
*/ | ||
public static PublicKey extractPublicKey(String fileName) throws Exception { | ||
byte[] keyBytes = Files.readAllBytes(Paths.get(fileName)); | ||
|
||
X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes); | ||
KeyFactory kf = KeyFactory.getInstance("EC"); | ||
return kf.generatePublic(spec); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters